/**
Theme Name: Astra Child
Author: Clic&Post
Author URI: https://www.clicandpost.com
Description: Astra is the fastest, fully customizable & beautiful theme suitable for blogs, personal portfolios and business websites. It is very lightweight (less than 50KB on frontend) and offers unparalleled speed. Built with SEO in mind, Astra comes with schema.org code integrated so search engines will love your site. Astra offers plenty of sidebar options and widget areas giving you a full control for customizations. Furthermore, we have included special features and templates so feel free to choose any of your favorite page builder plugin to create pages flexibly. Some of the other features: # WooCommerce Ready # Responsive # Compatible with major plugins # Translation Ready # Extendible with premium addons # Regularly updated # Designed, Developed, Maintained & Supported by Brainstorm Force. Looking for a perfect base theme? Look no further. Astra is fast, fully customizable and beautiful theme!
Version: 1.0.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: astra-child
Template: astra
*/

function custom_search_form() {
    ob_start();
    ?>
    <form class="custom-search-form" action="<?php echo home_url('/'); ?>" method="get">
        <input type="hidden" name="post_type" value="coches" />

        <div class="form-group">
            <label for="marca">Marca:</label>
            <select name="marca" id="marca">
                <option value="">Selecciona una marca</option>
                <?php
                $marcas = get_terms(array(
                    'taxonomy' => 'marca',
                    'hide_empty' => false,
                ));
                foreach ($marcas as $marca) {
                    echo '<option value="' . $marca->slug . '">' . $marca->name . '</option>';
                }
                ?>
            </select>
        </div>

        <div class="form-group">
            <label for="modelo">Modelo:</label>
            <select name="modelo" id="modelo">
                <option value="">Selecciona un modelo</option>
                <?php
                $modelos = get_terms(array(
                    'taxonomy' => 'modelo',
                    'hide_empty' => false,
                ));
                foreach ($modelos as $modelo) {
                    echo '<option value="' . $modelo->slug . '">' . $modelo->name . '</option>';
                }
                ?>
            </select>
        
        </div>

        <div class="form-group">
            <label for="combustible">Combustible:</label>
            <select name="combustible" id="combustible">
                <option value="">Selecciona un tipo de combustible</option>
                <?php
                $combustibles = get_terms(array(
                    'taxonomy' => 'combustible',
                    'hide_empty' => false,
                ));
                foreach ($combustibles as $combustible) {
                    echo '<option value="' . $combustible->slug . '">' . $combustible->name . '</option>';
                }
                ?>
            </select>
        </div>

        <div class="form-group">
            <label for="transmision">Transmisión:</label>
            <select name="transmision" id="transmision">
                <option value="">Selecciona un tipo de transmisión</option>
                <?php
                $transmisiones = get_terms(array(
                    'taxonomy' => 'transmision',
                    'hide_empty' => false,
                ));
                foreach ($transmisiones as $transmision) {
                    echo '<option value="' . $transmision->slug . '">' . $transmision->name . '</option>';
                }
                ?>
            </select>
        </div>

        <div class="form-group">
            <label for="km_maximo">Km. Máximo:</label>
            <select name="km_maximo" id="km_maximo">
                <option value="">Selecciona el kilometraje máximo</option>
                <?php
                $kilometrajes = get_terms(array(
                    'taxonomy' => 'kilometraje',
                    'hide_empty' => false,
                ));
                foreach ($kilometrajes as $km) {
                    echo '<option value="' . $km->slug . '">' . $km->name . '</option>';
                }
                ?>
            </select>
        </div>

        <div class="form-group">
            <label for="precio_maximo">Precio Máximo:</label>
            <select name="precio_maximo" id="precio_maximo">
                <option value="">Selecciona el precio máximo</option>
                <?php
                $precios = get_terms(array(
                    'taxonomy' => 'precio_maximo',
                    'hide_empty' => false,
                ));
                foreach ($precios as $precio) {
                    echo '<option value="' . $precio->slug . '">' . $precio->name . '</option>';
                }
                ?>
            </select>
        </div>

        <div class="form-group">
            <label for="s">Buscar:</label>
            <input type="text" name="s" id="s" placeholder="Buscar..." />
        </div>

        <div class="form-group">
            <input type="submit" value="Buscar" />
        </div>
    </form>
    <?php
    return ob_get_clean();
}
add_shortcode('custom_search_form', 'custom_search_form');

// PARA LOS RESULTADOS DE BUSQUEDA
function redirect_search_results() {
    if (is_search() && !empty($_GET['s'])) {
        wp_redirect(home_url("/resultados-de-busqueda-personalizados/?s=") . urlencode(get_query_var('s')));
        exit();
    }
}
add_action('template_redirect', 'redirect_search_results');



/* Asegura que el lightbox cubra toda la pantalla */
.lightboxOverlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    z-index: 9999;
}

.lightboxOverlay.active {
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Estilo para las imágenes dentro del lightbox */
.lightboxOverlay img {
    max-width: 90%;
    max-height: 90%;
}


.galeria-lightbox img {
    width: 150px; /* Fijamos el ancho de las miniaturas */
    height: 150px; /* Fijamos la altura de las miniaturas */
    object-fit: cover; /* Asegura que las imágenes se recorten de forma uniforme */
    margin: 10px;
    border-radius: 8px; /* Opción para dar un borde redondeado */
    box-shadow: 0 2px 5px rgba(0,0,0,0.2); /* Añade una ligera sombra para que resalten */
    display: inline-block; /* Asegura que las imágenes se alineen correctamente */
}




