<?php
/**
 * Map Preloader Template
 *
 * Displays animated placeholder for map while loading.
 * 
 * HOW TO OVERRIDE THIS TEMPLATE:
 * 1. Copy this file to: wp-content/themes/your-theme/havenlytics/preloaders/map.php
 * 2. Modify the copied file to customize the map preloader
 *
 * @package     Havenlytics
 * @subpackage  Templates/Preloaders
 * @since       2.2.0
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

$hvnly_animation_class = function_exists( 'hvnly_get_preloader_animation_class' ) ? hvnly_get_preloader_animation_class() : 'hvnly-shimmer';
?>

<div class="hvnly-map-preloader hvnly-preloader-container" id="hvnly-map-preloader" data-component="map">
    <div class="hvnly-map-preloader-container">
        <!-- Map Placeholder with Pulse Animation -->
        <div class="hvnly-map-preloader-header">
            <div class="hvnly-map-preloader-icon <?php echo esc_attr( $hvnly_animation_class ); ?>">
                <i class="fas fa-map-marked-alt"></i>
            </div>
            <div class="hvnly-map-preloader-title <?php echo esc_attr( $hvnly_animation_class ); ?>"></div>
        </div>

        <!-- Map Canvas Placeholder -->
        <div class="hvnly-map-preloader-canvas <?php echo esc_attr( $hvnly_animation_class ); ?>">
            <div class="hvnly-map-preloader-pulse"></div>
            <div class="hvnly-map-preloader-marker-container">
                <div class="hvnly-map-preloader-marker"></div>
                <div class="hvnly-map-preloader-marker hvnly-map-preloader-marker-2"></div>
                <div class="hvnly-map-preloader-marker hvnly-map-preloader-marker-3"></div>
            </div>
        </div>

        <!-- Map Controls Placeholder -->
        <div class="hvnly-map-preloader-controls">
            <div class="hvnly-map-preloader-control <?php echo esc_attr( $hvnly_animation_class ); ?>"></div>
            <div class="hvnly-map-preloader-control <?php echo esc_attr( $hvnly_animation_class ); ?>"></div>
        </div>
    </div>
</div>

<style>
/* Map Preloader Styles - Inline within template for easy override */
.hvnly-map-preloader {
    width: 100%;
    height: 500px;
    background: var(--hvnly-color-bg-light, #f8f9fa);
    border-radius: var(--hvnly-card-radius, 8px);
    overflow: hidden;
    position: relative;
}

.hvnly-map-preloader-container {
    width: 100%;
    height: 100%;
    position: relative;
    padding: 1rem;
}

.hvnly-map-preloader-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.hvnly-map-preloader-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(108, 96, 254, 0.1);
}

.hvnly-map-preloader-icon i {
    color: var(--hvnly-brand-primary, #6C60FE);
    font-size: 16px;
}

.hvnly-map-preloader-title {
    width: 150px;
    height: 20px;
    border-radius: 4px;
}

.hvnly-map-preloader-canvas {
    width: 100%;
    height: calc(100% - 60px);
    border-radius: 8px;
    position: relative;
    overflow: hidden;
}

.hvnly-map-preloader-pulse {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100px;
    height: 100px;
    margin: -50px 0 0 -50px;
    background: rgba(108, 96, 254, 0.15);
    border-radius: 50%;
    animation: hvnly-map-pulse 2s ease-in-out infinite;
}

.hvnly-map-preloader-marker-container {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.hvnly-map-preloader-marker {
    width: 30px;
    height: 42px;
    background: var(--hvnly-brand-primary, #6C60FE);
    border-radius: 50% 50% 50% 0;
    transform: rotate(-45deg);
    position: relative;
    animation: hvnly-map-bounce 1.5s ease-in-out infinite;
}

.hvnly-map-preloader-marker::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 8px;
    width: 14px;
    height: 14px;
    background: var(--hvnly-color-white, #fff);
    border-radius: 50%;
    transform: rotate(45deg);
}

.hvnly-map-preloader-marker-2 {
    position: absolute;
    top: -30px;
    left: 40px;
    width: 20px;
    height: 28px;
    animation-delay: 0.5s;
}

.hvnly-map-preloader-marker-3 {
    position: absolute;
    top: 20px;
    left: -30px;
    width: 24px;
    height: 34px;
    animation-delay: 1s;
}

.hvnly-map-preloader-controls {
    position: absolute;
    bottom: 1rem;
    right: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.hvnly-map-preloader-control {
    width: 30px;
    height: 30px;
    border-radius: 4px;
}

@keyframes hvnly-map-pulse {
    0% {
        transform: scale(0.5);
        opacity: 0.5;
    }

    50% {
        transform: scale(1.2);
        opacity: 0.2;
    }

    100% {
        transform: scale(0.5);
        opacity: 0.5;
    }
}

@keyframes hvnly-map-bounce {

    0%,
    100% {
        transform: rotate(-45deg) translateY(0);
    }

    50% {
        transform: rotate(-45deg) translateY(-10px);
    }
}

@media (prefers-reduced-motion: reduce) {

    .hvnly-map-preloader-pulse,
    .hvnly-map-preloader-marker {
        animation: none;
    }
}

@media (max-width: 768px) {
    .hvnly-map-preloader {
        height: 400px;
    }
}
</style>