<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
/**
 * Template Name: Local SEO
 * Description: Local SEO audit form page with user's exact HTML design
 */
$plugin_url = defined( 'AVISION_PLUGIN_URL' ) ? AVISION_PLUGIN_URL : '/wordpress/wp-content/plugins/avision-dashboard/';
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Local SEO Diagnosis - Avision</title>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="<?php echo $plugin_url; ?>assets/css/local-seo.css">
</head>
<body<?php
$avi_ls_body = array();
if ( function_exists( 'rest_url' ) ) {
	$avi_ls_body[] = 'data-audit-register-url="' . esc_attr( rest_url( 'avision/v1/audit-register' ) ) . '"';
}
if ( function_exists( 'wp_create_nonce' ) ) {
	$avi_ls_body[] = 'data-wp-rest-nonce="' . esc_attr( wp_create_nonce( 'wp_rest' ) ) . '"';
}
echo $avi_ls_body ? ' ' . implode( ' ', $avi_ls_body ) : '';
?>>
    <header class="av-header">
        <div class="av-header-container">
            <a href="/" class="av-logo">Avi<span>sion</span></a>
            <nav class="av-nav">
                <a href="/" data-i18n="nav_home">Home</a>
                <a href="/local-seo" class="active" data-i18n="nav_local_seo">Local SEO</a>
                <a href="/demo-dashboard" data-i18n="nav_dashboard">Dashboard</a>
                <a href="/payment" data-i18n="nav_pricing">Pricing</a>
            </nav>
            <div class="av-header-flags">
                <img src="https://flagcdn.com/w40/us.png" alt="English" class="av-header-flag active" onclick="setLanguage('en')" id="header-btn-en">
                <img src="https://flagcdn.com/w40/fr.png" alt="French" class="av-header-flag" onclick="setLanguage('fr')" id="header-btn-fr">
                <img src="https://flagcdn.com/w40/es.png" alt="Spanish" class="av-header-flag" onclick="setLanguage('es')" id="header-btn-es">
            </div>
        </div>
    </header>

    <main class="av-main">
        <div class="av-form-container">
            <div class="av-lang-switcher" id="av-lang-switcher">
                <button class="av-lang-btn active" data-lang="en">🇺🇸</button>
                <button class="av-lang-btn" data-lang="fr">🇫🇷</button>
                <button class="av-lang-btn" data-lang="es">🇪🇸</button>
            </div>
            
            <div class="av-form-card">
                <h1 class="av-title" data-i18n="title">Local Visibility Diagnosis</h1>
                <p class="av-subtitle" data-i18n="subtitle">Discover what is blocking your inbound calls in 60 seconds.</p>
                
                <div id="avision-loading" class="av-loading">
                    <div class="av-spinner"></div>
                    <p class="av-loading-text" data-i18n="generating">Avi is analyzing your profile...</p>
                    <p class="av-loading-sub" data-i18n="please_wait">I am comparing your positioning with competitors...</p>
                </div>
                
                <form method="post" id="avision-audit-form" class="av-form">
                    <label class="av-label" data-i18n="business_name">Business Name (exactly as on your Google Profile)</label>
                    <input type="text" name="avision_business_name" class="av-input" required data-i18n-placeholder="business_placeholder" placeholder="Ex: Smith Dental Clinic - NYC">
                    
                    <label class="av-label" data-i18n="city">City</label>
                    <input type="text" name="avision_city" id="avision-audit-city" class="av-input" required autocomplete="address-level2" data-i18n-placeholder="city_placeholder" placeholder="Ex: New York">

                    <label class="av-label" data-i18n="country">Country</label>
                    <select name="avision_country" class="av-input av-select" required style="display:block; width:100%; min-height:2.5em; margin-bottom:1em;">
                        <option value="FR">France</option>
                        <option value="GB">United Kingdom</option>
                        <option value="US">USA</option>
                        <option value="ES">Spain</option>
                    </select>

                    <label class="av-label" data-i18n="neighborhood">Neighborhood / District</label>
                    <input type="text" name="avision_neighborhood" class="av-input" required data-i18n-placeholder="neighborhood_placeholder" placeholder="Ex: Manhattan, Downtown">
                    
                    <label class="av-label" data-i18n="category">Your Profession (as on your Google Profile)</label>
                    <input type="text" name="avision_category" id="avision-audit-category" class="av-input" required data-i18n-placeholder="category_placeholder" placeholder="Ex: Dentist, Plumber, Lawyer..." autocomplete="off">
                    
                    <label class="av-label" data-i18n="phone_label">Phone (optional, for your Google Business Profile)</label>
                    <input type="tel" name="avision_phone" class="av-input" autocomplete="tel" data-i18n-placeholder="phone_placeholder" placeholder="+33 6 12 34 56 78">
                    
                    <label class="av-label" data-i18n="email_label">Your Professional Email (to receive the report)</label>
                    <input type="email" name="avision_email" class="av-input" required data-i18n-placeholder="email_placeholder" placeholder="contact@company.com">
                    
                    <button type="submit" class="av-submit-btn" data-i18n="submit_btn">Start Free Analysis →</button>
                    
                    <div class="av-trust-box">
                        <span class="av-trust-title" data-i18n="trust_title">It's free and no obligation.</span>
                        <ul class="av-trust-list">
                            <li>✅ <span data-i18n="trust_1">Real-time analysis (no outdated databases).</span></li>
                            <li>🔒 <span data-i18n="trust_2">Your data remains 100% confidential.</span></li>
                            <li>📧 <span data-i18n="trust_3">No spam, just your report.</span></li>
                        </ul>
                    </div>
                </form>
            </div>
        </div>
        
        <section class="av-comparison-section">
            <h2 class="av-section-title" data-i18n="comp_title">Why choose Avi over an Agency?</h2>
            <div class="av-comp-table-container">
                <table class="av-comp-table">
                    <thead>
                        <tr>
                            <th class="av-comp-th av-agency" data-i18n="comp_agency">Classic SEO Agency</th>
                            <th class="av-comp-th av-avi" data-i18n="comp_avi">Avi (Artificial Intelligence)</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td class="av-comp-td"><span class="av-cross">✗</span> <span data-i18n="comp_price_agency">$500 / month</span></td>
                            <td class="av-comp-td"><span class="av-check">✓</span> <span data-i18n="comp_price_avi">$99 (One-time payment)</span></td>
                        </tr>
                        <tr>
                            <td class="av-comp-td"><span class="av-cross">✗</span> <span data-i18n="comp_delay_agency">3 weeks delay</span></td>
                            <td class="av-comp-td"><span class="av-check">✓</span> <span data-i18n="comp_delay_avi">Instant (60 seconds)</span></td>
                        </tr>
                        <tr>
                            <td class="av-comp-td"><span class="av-cross">✗</span> <span data-i18n="comp_report_agency">Technical jargon reports</span></td>
                            <td class="av-comp-td"><span class="av-check">✓</span> <span data-i18n="comp_report_avi">Step-by-step Action Plan</span></td>
                        </tr>
                        <tr>
                            <td class="av-comp-td"><span class="av-cross">✗</span> <span data-i18n="comp_contract_agency">6-12 month contract</span></td>
                            <td class="av-comp-td"><span class="av-check">✓</span> <span data-i18n="comp_contract_avi">No contract</span></td>
                        </tr>
                        <tr>
                            <td class="av-comp-td"><span class="av-cross">✗</span> <span data-i18n="comp_support_agency">Email Support (48h)</span></td>
                            <td class="av-comp-td"><span class="av-check">✓</span> <span data-i18n="comp_support_avi">Chat Assistant 24/7</span></td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </section>
        
        <section class="av-demo-section">
            <h3 class="av-demo-title" data-i18n="demo_chat_title">See Avi in action:</h3>
            <div class="av-demo-chat-box">
                <div class="av-demo-msg-user" data-i18n="demo_user_msg">Avi, I just got a 1-star review that is unfair. What should I answer?</div>
                <div class="av-demo-msg-avi">
                    <span class="av-demo-avatar">🤖</span>
                    <span data-i18n="demo_avi_msg">Don't panic. Here is a diplomatic response to turn this situation around: "Hello [Name], we are surprised by this feedback as it does not reflect our standards..."</span>
                </div>
            </div>
        </section>
        
        <section class="av-reviews-section">
            <h2 class="av-section-title" data-i18n="review_title">They unlocked their growth</h2>
            <div class="av-reviews-scroll">
                <div class="av-review-card">
                    <span class="av-stars">★★★★★</span>
                    <p class="av-review-text" data-i18n="rev_1_text">"I finally understood why I wasn't ranking. The 'Missing Keywords' section was a shock. I applied the changes and saw results in 3 weeks."</p>
                    <div class="av-review-author">
                        <div class="av-author-avatar av-av-1">MD</div>
                        <span data-i18n="rev_1_auth">Mark D. - Osteopath</span>
                    </div>
                </div>
                <div class="av-review-card">
                    <span class="av-stars">★★★★★</span>
                    <p class="av-review-text" data-i18n="rev_2_text">"My agency charged me $500/month for reports I didn't understand. Avi gave me a clear roadmap in 1 minute."</p>
                    <div class="av-review-author">
                        <div class="av-author-avatar av-av-2">SL</div>
                        <span data-i18n="rev_2_auth">Sarah L. - Restaurant Owner</span>
                    </div>
                </div>
                <div class="av-review-card">
                    <span class="av-stars">★★★★★</span>
                    <p class="av-review-text" data-i18n="rev_3_text">"I'm not technical at all. The step-by-step guide for the first 30 days is exactly what I needed to organize my team."</p>
                    <div class="av-review-author">
                        <div class="av-author-avatar av-av-3">JP</div>
                        <span data-i18n="rev_3_auth">James P. - Plumber</span>
                    </div>
                </div>
                <div class="av-review-card">
                    <span class="av-stars">★★★★★</span>
                    <p class="av-review-text" data-i18n="rev_4_text">"The Chat Assistant is incredible. I received a bad review at 10 PM, asked Avi, and he wrote the perfect response instantly. It saved my reputation."</p>
                    <div class="av-review-author">
                        <div class="av-author-avatar av-av-4">ER</div>
                        <span data-i18n="rev_4_auth">Elena R. - Beauty Salon</span>
                    </div>
                </div>
                <div class="av-review-card">
                    <span class="av-stars">★★★★★</span>
                    <p class="av-review-text" data-i18n="rev_5_text">"Honest and direct. It doesn't promise miracles, but gives a solid logic. My profile views are up 20% this month."</p>
                    <div class="av-review-author">
                        <div class="av-author-avatar av-av-5">DK</div>
                        <span data-i18n="rev_5_auth">David K. - Lawyer</span>
                    </div>
                </div>
                <div class="av-review-card">
                    <span class="av-stars">★★★★★</span>
                    <p class="av-review-text" data-i18n="rev_6_text">"It's not just a PDF report. Having Avi available 24/7 to write my Facebook posts or analyze competitors is a game changer. It feels like having a Marketing Director in my pocket."</p>
                    <div class="av-review-author">
                        <div class="av-author-avatar av-av-6">MT</div>
                        <span data-i18n="rev_6_auth">Mike T. - Gym Owner</span>
                    </div>
                </div>
            </div>
        </section>
        
        <section class="av-cta-section">
            <a href="/demo-dashboard" class="av-cta-btn" data-i18n="cta_final">🚀 Access My Dashboard</a>
            <p class="av-cta-sub" data-i18n="cta_sub">No credit card required for demo access.</p>
            <div class="av-trust-badges">
                <span class="av-trust-item">🔒 Secure Payment</span>
                <span class="av-trust-item">⚡ <span data-i18n="guarantee_badge">Instant Access</span></span>
            </div>
        </section>
    </main>
    
    <div class="av-chat-widget">
        <div class="av-chat-btn" onclick="toggleChatWidget()">
            <span class="av-chat-tooltip" data-i18n="chat_bubble">Need help?</span>
            <span class="av-chat-icon">💬</span>
        </div>
        <div class="av-chat-window" id="av-chat-window">
            <div class="av-chat-header">
                <span class="av-chat-status"></span>
                <span data-i18n="chat_header">Avi - Your AI Coach</span>
            </div>
            <div class="av-chat-body">
                <div class="av-chat-msg" data-i18n="chat_welcome">Hello! I am Avi. Once unlocked, I will be your personal consultant to manage your reputation, strategy, and posts.</div>
            </div>
            <div class="av-chat-input-area">
                <input type="text" class="av-chat-input" disabled data-i18n-placeholder="chat_placeholder" placeholder="🔒 Reserved for Premium Members">
            </div>
        </div>
    </div>
    
    <script>
    const translations = {
        en: {
            nav_home: "Home",
            nav_local_seo: "Local SEO",
            nav_dashboard: "Dashboard",
            nav_pricing: "Pricing",
            title: "Local Visibility Diagnosis",
            subtitle: "Discover what is blocking your inbound calls in 60 seconds.",
            business_name: "Business Name (exactly as on your Google Profile)",
            business_placeholder: "Ex: Smith Dental Clinic - NYC",
            city: "City",
            country: "Country",
            city_placeholder: "Ex: New York",
            neighborhood: "Neighborhood / District",
            neighborhood_placeholder: "Ex: Manhattan, Downtown",
            category: "Your Profession (as on your Google Profile)",
            category_placeholder: "Ex: Dentist, Plumber, Lawyer...",
            phone_label: "Phone (optional, for your Google Business Profile)",
            phone_placeholder: "e.g. +1 555 123 4567",
            email_label: "Your Professional Email (to receive the report)",
            email_placeholder: "contact@company.com",
            submit_btn: "Start Free Analysis →",
            generating: "Avi is analyzing your profile...",
            please_wait: "I am comparing your positioning with competitors...",
            trust_title: "It's free and no obligation.",
            trust_1: "Real-time analysis (no outdated databases).",
            trust_2: "Your data remains 100% confidential.",
            trust_3: "No spam, just your report.",
            comp_title: "Why choose Avi over an Agency?",
            comp_agency: "Classic SEO Agency",
            comp_avi: "Avi (Artificial Intelligence)",
            comp_price_agency: "$500 / month",
            comp_price_avi: "$99 (One-time payment)",
            comp_delay_agency: "3 weeks delay",
            comp_delay_avi: "Instant (60 seconds)",
            comp_report_agency: "Technical jargon reports",
            comp_report_avi: "Step-by-step Action Plan",
            comp_contract_agency: "6-12 month contract",
            comp_contract_avi: "No contract",
            comp_support_agency: "Email Support (48h)",
            comp_support_avi: "Chat Assistant 24/7",
            demo_chat_title: "See Avi in action:",
            demo_user_msg: "Avi, I just got a 1-star review that is unfair. What should I answer?",
            demo_avi_msg: "Don't panic. Here is a diplomatic response to turn this situation around: \"Hello [Name], we are surprised by this feedback as it does not reflect our standards...\"",
            review_title: "They unlocked their growth",
            cta_final: "🚀 Access My Dashboard",
            cta_sub: "No credit card required for demo access.",
            guarantee_badge: "Instant Access",
            chat_bubble: "Need help?",
            chat_header: "Avi - Your AI Coach",
            chat_welcome: "Connecting to AVI...",
            chat_placeholder: "🔒 Reserved for Premium Members",
            rev_1_text: "\"I finally understood why I wasn't ranking. The 'Missing Keywords' section was a shock. I applied the changes and saw results in 3 weeks.\"",
            rev_1_auth: "Mark D. - Osteopath",
            rev_2_text: "\"My agency charged me $500/month for reports I didn't understand. Avi gave me a clear roadmap in 1 minute.\"",
            rev_2_auth: "Sarah L. - Restaurant Owner",
            rev_3_text: "\"I'm not technical at all. The step-by-step guide for the first 30 days is exactly what I needed to organize my team.\"",
            rev_3_auth: "James P. - Plumber",
            rev_4_text: "\"The Chat Assistant is incredible. I received a bad review at 10 PM, asked Avi, and he wrote the perfect response instantly. It saved my reputation.\"",
            rev_4_auth: "Elena R. - Beauty Salon",
            rev_5_text: "\"Honest and direct. It doesn't promise miracles, but gives a solid logic. My profile views are up 20% this month.\"",
            rev_5_auth: "David K. - Lawyer",
            rev_6_text: "\"It's not just a PDF report. Having Avi available 24/7 to write my Facebook posts or analyze competitors is a game changer. It feels like having a Marketing Director in my pocket.\"",
            rev_6_auth: "Mike T. - Gym Owner"
        },
        fr: {
            nav_home: "Accueil",
            nav_local_seo: "SEO Local",
            nav_dashboard: "Tableau de bord",
            nav_pricing: "Tarifs",
            title: "Diagnostic de Visibilite Locale",
            subtitle: "Decouvrez ce qui bloque vos appels entrants en 60 secondes.",
            business_name: "Nom de votre entreprise (tel qu'ecrit sur votre fiche Google)",
            business_placeholder: "Ex: Cabinet Dentaire Dupont - Lyon Centre",
            city: "Ville",
            country: "Pays",
            city_placeholder: "Ex: Lyon",
            neighborhood: "Quartier / Arrondissement",
            neighborhood_placeholder: "Ex: 3e arr., Presqu'ile",
            category: "Votre metier (tel qu'ecrit sur votre fiche Google)",
            category_placeholder: "Ex: Dentiste, Plombier, Avocat...",
            phone_label: "Téléphone (facultatif, comme sur votre fiche Google)",
            phone_placeholder: "Ex : 06 12 34 56 78",
            email_label: "Votre Email Pro (pour recevoir le rapport)",
            email_placeholder: "contact@votre-entreprise.com",
            submit_btn: "Lancer l'analyse gratuite →",
            generating: "Avi analyse votre fiche...",
            please_wait: "Je compare votre positionnement avec vos concurrents...",
            trust_title: "C'est gratuit et sans engagement.",
            trust_1: "Analyse en temps reel (pas de base obsolete).",
            trust_2: "Vos donnees restent confidentielles.",
            trust_3: "Pas de spam, juste votre rapport.",
            comp_title: "Pourquoi choisir Avi plutot qu'une Agence ?",
            comp_agency: "Agence SEO Classique",
            comp_avi: "Avi (Intelligence Artificielle)",
            comp_price_agency: "500 EUR / mois",
            comp_price_avi: "99 EUR (Paiement unique)",
            comp_delay_agency: "Delai de 3 semaines",
            comp_delay_avi: "Instantane (60 secondes)",
            comp_report_agency: "Rapports techniques illisibles",
            comp_report_avi: "Plan d'action \"Pas a Pas\"",
            comp_contract_agency: "Engagement de 6 a 12 mois",
            comp_contract_avi: "Sans engagement",
            comp_support_agency: "Support Email (48h)",
            comp_support_avi: "Assistant Chat 24/7",
            demo_chat_title: "Voyez Avi en action :",
            demo_user_msg: "Avi, je viens de recevoir un avis 1 etoile injuste. Quoi repondre ?",
            demo_avi_msg: "Pas de panique. Voici une reponse diplomatique pour retourner la situation a ton avantage : \"Bonjour [Nom], nous sommes surpris par ce retour qui ne reflete pas nos standards...\"",
            review_title: "Ils ont debloque leur croissance",
            cta_final: "🚀 Acceder a mon Espace de Travail",
            cta_sub: "Aucune carte bancaire requise pour l'acces demo.",
            guarantee_badge: "Acces Immediat",
            chat_bubble: "Une question ?",
            chat_header: "Avi - Votre Coach IA",
            chat_welcome: "Connexion à AVI...",
            chat_placeholder: "🔒 Reserve aux membres Premium",
            rev_1_text: "\"J'ai enfin compris pourquoi je n'etais pas visible. La section 'Mots Cles Manquants' a ete un choc. J'ai applique les changements et vu des resultats en 3 semaines.\"",
            rev_1_auth: "Marc D. - Osteopathe",
            rev_2_text: "\"Mon agence me facturait 500 EUR/mois pour des rapports que je ne comprenais pas. Avi m'a donne une feuille de route claire en 1 minute.\"",
            rev_2_auth: "Sophie L. - Restauratrice",
            rev_3_text: "\"Je ne suis pas technique du tout. Le guide pas-a-pas pour les 30 premiers jours est exactement ce qu'il me fallait pour organiser mon equipe.\"",
            rev_3_auth: "Julien P. - Plombier",
            rev_4_text: "\"L'assistant Chat est incroyable. J'ai eu un mauvais avis a 22h, j'ai demande a Avi et il m'a redige la reponse parfaite instantanement. Ca a sauve ma reputation.\"",
            rev_4_auth: "Elena R. - Institut de Beaute",
            rev_5_text: "\"Honnete et direct. Ca ne promet pas de miracles, mais une logique implacable. Mes vues profil sont en hausse de 20% ce mois-ci.\"",
            rev_5_auth: "David K. - Avocat",
            rev_6_text: "\"Ce n'est pas juste un rapport PDF. Avoir Avi dispo 24/7 pour rediger mes posts Facebook ou analyser mes concurrents change tout. C'est comme avoir un Directeur Marketing dans sa poche.\"",
            rev_6_auth: "Michel T. - Gerant Salle de Sport"
        },
        es: {
            nav_home: "Inicio",
            nav_local_seo: "SEO Local",
            nav_dashboard: "Panel de Control",
            nav_pricing: "Precios",
            title: "Diagnostico de Visibilidad Local",
            subtitle: "Descubra que esta bloqueando sus llamadas entrantes en 60 segundos.",
            business_name: "Nombre del negocio (tal como aparece en su perfil de Google)",
            business_placeholder: "Ej: Clinica Dental Perez - Madrid",
            city: "Ciudad",
            country: "País",
            city_placeholder: "Ej: Madrid",
            neighborhood: "Barrio / Distrito",
            neighborhood_placeholder: "Ej: Centro, Chamberi",
            category: "Su Profesion (tal como aparece en su perfil de Google)",
            category_placeholder: "Ej: Dentista, Fontanero, Abogado...",
            phone_label: "Teléfono (opcional, como en tu ficha de Google)",
            phone_placeholder: "Ej: +34 612 345 678",
            email_label: "Tu Email (para recibir el informe)",
            email_placeholder: "contacto@empresa.com",
            submit_btn: "Iniciar Analisis Gratuito →",
            generating: "Avi esta analizando su perfil...",
            please_wait: "Estoy comparando su posicionamiento con la competencia...",
            trust_title: "Es gratis y sin compromiso.",
            trust_1: "Analisis en tiempo real (sin bases obsoletas).",
            trust_2: "Sus datos permanecen confidenciales.",
            trust_3: "Sin spam, solo su informe.",
            comp_title: "Por que elegir Avi en lugar de una Agencia?",
            comp_agency: "Agencia SEO Clasica",
            comp_avi: "Avi (Inteligencia Artificial)",
            comp_price_agency: "500 EUR / mes",
            comp_price_avi: "99 EUR (Pago unico)",
            comp_delay_agency: "Demora de 3 semanas",
            comp_delay_avi: "Instantaneo (60 segundos)",
            comp_report_agency: "Informes tecnicos ilegibles",
            comp_report_avi: "Plan de accion \"Paso a Paso\"",
            comp_contract_agency: "Contrato de 6 a 12 meses",
            comp_contract_avi: "Sin compromiso",
            comp_support_agency: "Soporte Email (48h)",
            comp_support_avi: "Asistente Chat 24/7",
            demo_chat_title: "Vea a Avi en accion:",
            demo_user_msg: "Avi, acabo de recibir una resena injusta de 1 estrella. Que respondo?",
            demo_avi_msg: "No entres en panico. Aqui tienes una respuesta diplomatica para cambiar la situacion: \"Hola [Nombre], nos sorprende este comentario ya que no refleja nuestros estandares...\"",
            review_title: "Desbloquearon su crecimiento",
            cta_final: "🚀 Acceder a mi Panel de Control",
            cta_sub: "No se requiere tarjeta de credito para el acceso demo.",
            guarantee_badge: "Acceso Inmediato",
            chat_bubble: "Una pregunta?",
            chat_header: "Avi - Su Coach IA",
            chat_welcome: "Conectando a AVI...",
            chat_placeholder: "🔒 Reservado para miembros Premium",
            rev_1_text: "\"Por fin entendi por que no era visible. La seccion de 'Palabras Clave Faltantes' fue un shock. Aplique los cambios y vi resultados en 3 semanas.\"",
            rev_1_auth: "Marcos D. - Osteopata",
            rev_2_text: "\"Mi agencia me cobraba 500 EUR/mes por informes que no entendia. Avi me dio una hoja de ruta clara en 1 minuto.\"",
            rev_2_auth: "Sofia L. - Restaurante",
            rev_3_text: "\"No soy nada tecnico. La guia paso a paso para los primeros 30 dias es exactamente lo que necesitaba para organizar a mi equipo.\"",
            rev_3_auth: "Julian P. - Fontanero",
            rev_4_text: "\"El Asistente de Chat es increible. Recibi una mala resena a las 10 PM, le pregunte a Avi y me escribio la respuesta perfecta al instante. Salvo mi reputacion.\"",
            rev_4_auth: "Elena R. - Salon de Belleza",
            rev_5_text: "\"Honesto y directo. No promete milagros, pero si una logica solida. Mis vistas de perfil han subido un 20% este mes.\"",
            rev_5_auth: "David K. - Abogado",
            rev_6_text: "\"No es solo un informe PDF. Tener a Avi disponible 24/7 para escribir mis posts de Facebook o analizar competidores lo cambia todo. Es como tener un Director de Marketing en el bolsillo.\"",
            rev_6_auth: "Miguel T. - Gimnasio"
        }
    };
    
    let currentLanguage = 'en';
    
    function setLanguage(lang) {
        currentLanguage = lang;
        const t = translations[lang];
        
        document.querySelectorAll('[data-i18n]').forEach(el => {
            const key = el.getAttribute('data-i18n');
            if (t[key]) {
                el.textContent = t[key];
            }
        });
        
        document.querySelectorAll('[data-i18n-placeholder]').forEach(el => {
            const key = el.getAttribute('data-i18n-placeholder');
            if (t[key]) {
                el.placeholder = t[key];
            }
        });
        
        document.querySelectorAll('.av-lang-btn').forEach(btn => {
            btn.classList.remove('active');
            if (btn.dataset.lang === lang) btn.classList.add('active');
        });
        
        document.querySelectorAll('.av-header-flag').forEach(flag => {
            flag.classList.remove('active');
        });
        document.getElementById('header-btn-' + lang).classList.add('active');
        
        localStorage.setItem('avision_lang', lang);
        document.cookie = "avision_lang=" + lang + "; path=/; max-age=31536000";
    }
    
    function toggleChatWidget() {
        const chatWindow = document.getElementById('av-chat-window');
        chatWindow.style.display = chatWindow.style.display === 'block' ? 'none' : 'block';
    }
    
    document.addEventListener('DOMContentLoaded', function() {
        const urlParams = new URLSearchParams(window.location.search);
        const urlLang = urlParams.get('lang') || urlParams.get('avision_lang');
        const savedLang = localStorage.getItem('avision_lang');
        const cookieLang = document.cookie.split('; ').find(row => row.startsWith('avision_lang='));
        
        let detectedLang = urlLang || savedLang || (cookieLang ? cookieLang.split('=')[1] : null) || 'en';
        if (!['en', 'fr', 'es'].includes(detectedLang)) detectedLang = 'en';
        
        setLanguage(detectedLang);
        
        document.querySelectorAll('.av-lang-btn').forEach(btn => {
            btn.addEventListener('click', () => setLanguage(btn.dataset.lang));
        });
        
        const form = document.getElementById('avision-audit-form');
        if (form) {
            form.addEventListener('submit', function(e) {
                e.preventDefault();
                
                const btn = form.querySelector('button[type="submit"]');
                btn.disabled = true;
                btn.style.opacity = '0.7';
                btn.innerHTML = currentLanguage === 'fr' ? 'Analyse en cours...' : currentLanguage === 'es' ? 'Analizando...' : 'Analyzing...';
                form.style.display = 'none';
                document.getElementById('avision-loading').style.display = 'block';
                
                const company = form.querySelector('input[name="avision_business_name"]').value.trim();
                const cityInput = form.querySelector('#avision-audit-city') || form.querySelector('input[name="avision_city"]');
                const city = cityInput ? String(cityInput.value || '').trim() : '';
                const countryEl = form.querySelector('select[name="avision_country"]');
                const country = (countryEl && countryEl.value) ? String(countryEl.value).trim() : 'FR';
                const neighborhood = form.querySelector('input[name="avision_neighborhood"]').value.trim();
                const catInput = form.querySelector('#avision-audit-category') || form.querySelector('input[name="avision_category"]');
                const category = catInput ? String(catInput.value || '').trim() : '';
                const email = form.querySelector('input[name="avision_email"]').value.trim();
                const phoneEl = form.querySelector('input[name="avision_phone"]');
                const phone = phoneEl ? String(phoneEl.value || '').trim() : '';
                if (!city || city === '-' || city === '–' || city === '—') {
                    alert(currentLanguage === 'fr' ? "La ville est obligatoire." : currentLanguage === 'es' ? "La ciudad es obligatoria." : "City is required.");
                    btn.disabled = false;
                    btn.style.opacity = '1';
                    btn.innerHTML = document.querySelector('[data-i18n="submit_btn"]') ? translations[currentLanguage].submit_btn : 'Start Free Analysis →';
                    form.style.display = 'block';
                    document.getElementById('avision-loading').style.display = 'none';
                    if (cityInput) cityInput.focus();
                    return;
                }
                if (!neighborhood) {
                    alert(currentLanguage === 'fr' ? "Le quartier / arrondissement est obligatoire." : currentLanguage === 'es' ? "El barrio / distrito es obligatorio." : "Neighborhood / District is required.");
                    btn.disabled = false;
                    btn.style.opacity = '1';
                    btn.innerHTML = document.querySelector('[data-i18n="submit_btn"]') ? translations[currentLanguage].submit_btn : 'Start Free Analysis →';
                    form.style.display = 'block';
                    document.getElementById('avision-loading').style.display = 'none';
                    return;
                }
                localStorage.setItem('avision_company', company);
                localStorage.setItem('avision_city', city);
                localStorage.setItem('avision_country', country);
                localStorage.setItem('avision_neighborhood', neighborhood);
                localStorage.setItem('avision_category', category);
                localStorage.setItem('avision_email', email);
                localStorage.setItem('avision_user_email', email);
                if (phone) {
                    localStorage.setItem('avision_phone', phone);
                } else {
                    localStorage.removeItem('avision_phone');
                }
                localStorage.setItem('avision_lang', currentLanguage);
                try {
                    if (typeof sessionStorage !== 'undefined') {
                        sessionStorage.setItem('avision_company', company);
                        sessionStorage.setItem('avision_city', city);
                        sessionStorage.setItem('avision_country', country);
                        sessionStorage.setItem('avision_neighborhood', neighborhood);
                        sessionStorage.setItem('avision_category', category);
                        sessionStorage.setItem('avision_email', email);
                        sessionStorage.setItem('avision_user_email', email);
                        if (phone) sessionStorage.setItem('avision_phone', phone);
                        else sessionStorage.removeItem('avision_phone');
                        sessionStorage.setItem('avision_lang', currentLanguage);
                    }
                } catch (eSess) {}
                
                const randomScore = Math.floor(Math.random() * 30) + 25;
                const auditRegisterUrl = document.body.dataset.auditRegisterUrl || (window.location.origin + '/wp-json/avision/v1/audit-register');
                var aviLsRestHeaders = { 'Content-Type': 'application/json' };
                if (document.body.dataset.wpRestNonce) aviLsRestHeaders['X-WP-Nonce'] = document.body.dataset.wpRestNonce;
                fetch(auditRegisterUrl, {
                    method: 'POST',
                    headers: aviLsRestHeaders,
                    credentials: 'include',
                    body: JSON.stringify({
                        email: email,
                        business_name: company,
                        city: city,
                        country: country,
                        neighborhood: neighborhood,
                        category: category,
                        phone: phone || undefined,
                        language: currentLanguage,
                        score: randomScore
                    })
                })
                .then(function(res) { return res.json().then(function(data) { return { ok: res.ok, data: data }; }); })
                .then(function(result) {
                    var params = new URLSearchParams({
                        company: company,
                        city: city,
                        country: country,
                        neighborhood: neighborhood,
                        category: category,
                        email: email,
                        lang: currentLanguage,
                        score: randomScore
                    });
                    if (phone) {
                        params.set('phone', phone);
                    }
                    if (result.ok && result.data && result.data.success) {
                        if (result.data.promotion_expires_at) {
                            var expiresAt = result.data.promotion_expires_at;
                            localStorage.setItem('avision_promotion_expires_at', expiresAt);
                            document.cookie = 'avision_promotion_expires_at=' + encodeURIComponent(expiresAt) + '; path=/; max-age=86400; samesite=lax';
                        }
                        if (result.data.sid) {
                            params.set('sid', result.data.sid);
                        }
                    }
                    setTimeout(function() {
                        window.location.href = '/demo-dashboard?' + params.toString();
                    }, 2000);
                })
                .catch(function() {
                    var params = new URLSearchParams({
                        company: company,
                        city: city,
                        country: country,
                        neighborhood: neighborhood,
                        category: category,
                        email: email,
                        lang: currentLanguage,
                        score: randomScore
                    });
                    if (phone) {
                        params.set('phone', phone);
                    }
                    setTimeout(function() {
                        window.location.href = '/demo-dashboard?' + params.toString();
                    }, 2000);
                });
            });
        }
        
        const businessName = urlParams.get('business_name');
        if (businessName) {
            const nameInput = document.querySelector('input[name="avision_business_name"]');
            if (nameInput) {
                nameInput.value = businessName;
                const cityInput = document.querySelector('input[name="avision_city"]');
                if (cityInput) setTimeout(() => cityInput.focus(), 100);
            }
        }
    });
    </script>
</body>
</html>
