@model OnlyOneAccessTemplate.Models.SiteConfiguration
@{
    ViewData["Title"] = ViewBag.Title ?? Model.SiteTitle;
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<!-- Google AdSense - Script Global -->
@section Head {
    @if (ViewBag.GoogleAdsEnabled == true && !string.IsNullOrEmpty(ViewBag.GoogleAdsPublisher))
    {
        <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=@ViewBag.GoogleAdsPublisher"
                crossorigin="anonymous"></script>
    }
    
    <style>
        .ad-container { margin: 15px 0; text-align: center; min-height: 50px; }
        .ad-banner { min-height: 90px; }
        .ad-rectangle { min-height: 250px; }
        .ad-sidebar { min-height: 600px; }
        .ad-sticky { position: sticky; top: 20px; z-index: 100; }
        .converter-section { background: #f8f9fa; }
        
        @@media (max-width: 768px) {
            .ad-sidebar { display: none !important; }
            .ad-rectangle { min-height: 200px; }
            .main-content { padding: 0 10px; }
        }
        
        @@media (min-width: 1200px) {
            .ad-sidebar { min-height: 600px; }
        }
    </style>
}

<!-- Banner Superior -->
@{
    ViewBag.AdPosition = "banner-top";
    ViewBag.AdSlotId = ViewBag.AdSlots?.BannerTop ?? "1234567890";
    ViewBag.AdFormat = "auto";
    ViewBag.AdCssClass = "ad-container ad-banner";
    ViewBag.ShowOnMobile = true;
    ViewBag.ShowOnDesktop = true;
}
@await Html.PartialAsync("_AdUnit")

<div class="container-fluid">
    <div class="row">
        <!-- Sidebar Esquerda com Anúncios -->
        <div class="col-xl-2 col-lg-2 d-none d-lg-block">
            @{
                ViewBag.AdPosition = "sidebar-left";
                ViewBag.AdSlotId = ViewBag.AdSlots?.SidebarLeft ?? "2345678901";
                ViewBag.AdFormat = "vertical";
                ViewBag.AdSize = "; width: 300px; height: 600px;";
                ViewBag.AdCssClass = "ad-container ad-sidebar";
                ViewBag.IsSticky = true;
                ViewBag.ShowOnMobile = false;
                ViewBag.ShowOnDesktop = true;
            }
            @await Html.PartialAsync("_AdUnit")
        </div>

        <!-- Conteúdo Principal -->
        <div class="col-xl-8 col-lg-8 col-md-12 main-content">
            <!-- Seção Principal do Conversor -->
            <section class="converter-section py-4">
                <div class="container">
                    <div class="row justify-content-center">
                        <div class="col-lg-11">
                            <!-- Título e Descrição -->
                            <div class="text-center mb-4">
                                <h1 class="display-4 fw-bold text-gradient mb-3">
                                    @(ViewBag.ConverterTitle ?? "CONVERSOR ONLINE")
                                </h1>
                                <p class="lead text-green-light mb-4">
                                    @(ViewBag.ConverterDescription ?? "Converta seus arquivos de forma rápida e segura")
                                </p>
                            </div>

                            <!-- Anúncio Retangular Antes do Conversor -->
                            @{
                                ViewBag.AdPosition = "rectangle-pre-converter";
                                ViewBag.AdSlotId = ViewBag.AdSlots?.RectanglePre ?? "3456789012";
                                ViewBag.AdFormat = "rectangle";
                                ViewBag.AdSize = "; width: 300px; height: 250px;";
                                ViewBag.AdCssClass = "ad-container ad-rectangle mb-4";
                                ViewBag.IsSticky = false;
                                ViewBag.ShowOnMobile = true;
                                ViewBag.ShowOnDesktop = true;
                            }
                            @await Html.PartialAsync("_AdUnit")

                            <!-- Card do Conversor -->
                            <div class="card shadow-lg border-0 rounded-3">
                                <div class="card-body p-4">
                                    <!-- Steps do Processo -->
                                    <div class="row text-center mb-4">
                                        <div class="col-md-4 mb-3">
                                            <div class="step-indicator">
                                                <span class="badge bg-gradient-green rounded-circle p-3 fs-5 mb-2 text-white">1</span>
                                                <h6 class="fw-bold text-green-light">@(ViewBag.Step1Title ?? "Digite")</h6>
                                                <small class="text-muted">@(ViewBag.Step1Description ?? "Digite seu texto")</small>
                                            </div>
                                        </div>
                                        <div class="col-md-4 mb-3">
                                            <div class="step-indicator">
                                                <span class="badge bg-gradient-green rounded-circle p-3 fs-5 mb-2 text-white">2</span>
                                                <h6 class="fw-bold text-green-light">@(ViewBag.Step2Title ?? "Converter")</h6>
                                                <small class="text-muted">@(ViewBag.Step2Description ?? "Clique para converter")</small>
                                            </div>
                                        </div>
                                        <div class="col-md-4 mb-3">
                                            <div class="step-indicator">
                                                <span class="badge bg-gradient-green rounded-circle p-3 fs-5 mb-2 text-white">3</span>
                                                <h6 class="fw-bold text-green-light">@(ViewBag.Step3Title ?? "Copiar")</h6>
                                                <small class="text-muted">@(ViewBag.Step3Description ?? "Copie o resultado")</small>
                                            </div>
                                        </div>
                                    </div>

                                    <!-- Área do Conversor -->
                                    <div id="converter-container">
                                        @await Html.PartialAsync("_ConverterWidget")
                                    </div>

                                    <!-- Informações Adicionais -->
                                    <div class="row mt-4">
                                        <div class="col-md-6">
                                            <div class="d-flex align-items-center mb-2">
                                                <i class="fas fa-shield-alt text-success me-2"></i>
                                                <small class="text-green-light fw-bold">@(ViewBag.SecurityText ?? "Seus dados estão seguros")</small>
                                            </div>
                                        </div>
                                        <div class="col-md-6">
                                            <div class="d-flex align-items-center mb-2">
                                                <i class="fas fa-bolt text-success me-2"></i>
                                                <small class="text-green-light fw-bold">@(ViewBag.FileInfoText ?? "Processamento rápido e seguro")</small>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <!-- Anúncio Retangular Após o Conversor -->
                            @{
                                ViewBag.AdPosition = "rectangle-post-converter";
                                ViewBag.AdSlotId = ViewBag.AdSlots?.RectanglePost ?? "4567890123";
                                ViewBag.AdFormat = "rectangle";
                                ViewBag.AdSize = "; width: 300px; height: 250px;";
                                ViewBag.AdCssClass = "ad-container ad-rectangle mt-4";
                                ViewBag.IsSticky = false;
                                ViewBag.ShowOnMobile = true;
                                ViewBag.ShowOnDesktop = true;
                            }
                            @await Html.PartialAsync("_AdUnit")
                        </div>
                    </div>
                </div>
            </section>

            <!-- Anúncio In-Feed Entre Seções -->
            @{
                ViewBag.AdPosition = "in-feed";
                ViewBag.AdSlotId = ViewBag.AdSlots?.InFeed ?? "5678901234";
                ViewBag.AdFormat = "fluid";
                ViewBag.AdCssClass = "ad-container";
                ViewBag.IsSticky = false;
                ViewBag.ShowOnMobile = true;
                ViewBag.ShowOnDesktop = true;
            }
            @await Html.PartialAsync("_AdUnit")

            <!-- Seção de Benefícios -->
            <section class="benefits-section py-5">
                <div class="container">
                    <div class="row">
                        <div class="col-lg-10 mx-auto text-center mb-5">
                            <h2 class="h3 fw-bold mb-3 text-gradient">@(ViewBag.BenefitsTitle ?? "Por Que Usar Nossa Ferramenta?")</h2>
                            <p class="text-green-light">@(ViewBag.BenefitsSubtitle ?? "Descubra os benefícios de nossa solução")</p>
                        </div>
                    </div>

                    <div class="row g-4 justify-content-center">
                        <!-- Features (código existente) -->
                        <div class="col-md-6 col-lg-3">
                            <div class="text-center p-3">
                                <div class="feature-icon mb-3">
                                    <i class="fas fa-rocket fa-2x text-success"></i>
                                </div>
                                <h6 class="fw-bold text-green-light">@(ViewBag.Feature1Title ?? "Rápido e Fácil")</h6>
                                <small class="text-muted">@(ViewBag.Feature1Description ?? "Conversão instantânea")</small>
                            </div>
                        </div>
                        <div class="col-md-6 col-lg-3">
                            <div class="text-center p-3">
                                <div class="feature-icon mb-3">
                                    <i class="fas fa-shield-alt fa-2x text-success"></i>
                                </div>
                                <h6 class="fw-bold text-green-light">@(ViewBag.Feature2Title ?? "Seguro")</h6>
                                <small class="text-muted">@(ViewBag.Feature2Description ?? "Dados protegidos")</small>
                            </div>
                        </div>
                        <div class="col-md-6 col-lg-3">
                            <div class="text-center p-3">
                                <div class="feature-icon mb-3">
                                    <i class="fas fa-users fa-2x text-success"></i>
                                </div>
                                <h6 class="fw-bold text-green-light">@(ViewBag.Feature3Title ?? "Confiável")</h6>
                                <small class="text-muted">@(ViewBag.Feature3Description ?? "Resultados precisos")</small>
                            </div>
                        </div>
                        <div class="col-md-6 col-lg-3">
                            <div class="text-center p-3">
                                <div class="feature-icon mb-3">
                                    <i class="fas fa-clock fa-2x text-success"></i>
                                </div>
                                <h6 class="fw-bold text-green-light">Rápido</h6>
                                <small class="text-muted">Conversão em segundos</small>
                            </div>
                        </div>
                    </div>
                </div>
            </section>

            <!-- Anúncio Multiplex -->
            @{
                ViewBag.AdPosition = "multiplex";
                ViewBag.AdSlotId = ViewBag.AdSlots?.Multiplex ?? "6789012345";
                ViewBag.AdFormat = "autorelaxed";
                ViewBag.AdCssClass = "ad-container";
                ViewBag.IsSticky = false;
                ViewBag.ShowOnMobile = true;
                ViewBag.ShowOnDesktop = true;
            }
            @await Html.PartialAsync("_AdUnit")

            <!-- Seção CTA Final -->
@* 
            <section class="final-cta py-5">
                <div class="container">
                    <div class="row">
                        <div class="col-lg-8 mx-auto text-center">
                            <h2 class="h3 fw-bold mb-3 text-gradient">@(ViewBag.FinalCtaTitle ?? "Pronto para Converter?")</h2>
                            <p class="text-green-light mb-4">@(ViewBag.FinalCtaSubtitle ?? "Use nossa ferramenta gratuita agora mesmo")</p>
                            <a href="#converter-container" class="btn btn-primary btn-lg hover-lift">
                                @(ViewBag.FinalCtaButtonText ?? "Começar Conversão")
                            </a>
                        </div>
                    </div>
                </div>
            </section>

 *@
            </div>

        <!-- Sidebar Direita com Anúncios -->
        <div class="col-xl-2 col-lg-2 d-none d-lg-block">
            @{
                ViewBag.AdPosition = "sidebar-right";
                ViewBag.AdSlotId = ViewBag.AdSlots?.SidebarRight ?? "7890123456";
                ViewBag.AdFormat = "vertical";
                ViewBag.AdSize = "; width: 300px; height: 600px;";
                ViewBag.AdCssClass = "ad-container ad-sidebar";
                ViewBag.IsSticky = true;
                ViewBag.ShowOnMobile = false;
                ViewBag.ShowOnDesktop = true;
            }
            @await Html.PartialAsync("_AdUnit")

            <!-- Anúncio Quadrado Adicional na Sidebar -->
            <div class="mt-4">
                @{
                    ViewBag.AdPosition = "sidebar-square";
                    ViewBag.AdSlotId = ViewBag.AdSlots?.SidebarSquare ?? "8901234567";
                    ViewBag.AdFormat = "square";
                    ViewBag.AdSize = "; width: 250px; height: 250px;";
                    ViewBag.AdCssClass = "ad-container";
                    ViewBag.IsSticky = false;
                    ViewBag.ShowOnMobile = false;
                    ViewBag.ShowOnDesktop = true;
                }
                @await Html.PartialAsync("_AdUnit")
            </div>
        </div>
    </div>
</div>

<!-- Banner Inferior Mobile -->
@{
    ViewBag.AdPosition = "mobile-bottom";
    ViewBag.AdSlotId = ViewBag.AdSlots?.MobileBottom ?? "9012345678";
    ViewBag.AdFormat = "banner";
    ViewBag.AdSize = "; width: 320px; height: 50px;";
    ViewBag.AdCssClass = "fixed-bottom d-block d-md-none";
    ViewBag.IsSticky = false;
    ViewBag.ShowOnMobile = true;
    ViewBag.ShowOnDesktop = false;
}
<div class="@ViewBag.AdCssClass bg-white border-top p-2" style="z-index: 1050;" id="mobile-bottom-ad">
    <div class="d-flex justify-content-between align-items-center">
        @await Html.PartialAsync("_AdUnit")
        <button type="button" class="btn-close ms-2" onclick="document.getElementById('mobile-bottom-ad').style.display='none'"></button>
    </div>
</div>

<!-- Scripts específicos -->
@section Scripts {
    <script src="~/js/converter.js"></script>
    @{
        var converterType = ViewBag.ConverterType ?? "generic";
        var jsFileName = $"~/js/converters/{converterType.ToString().ToLower()}-converter.js";
    }
    <script src="@jsFileName"></script>
    
    <!-- Inicialização dos Anúncios -->
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // Inicializar conversor
            if (typeof initializeConverter === 'function') {
                initializeConverter();
            }
            
            // Inicializar anúncios do Google
            @if (ViewBag.GoogleAdsEnabled == true)
            {
                @Html.Raw("initializeGoogleAds();")
            }
        });
        
        function initializeGoogleAds() {
            try {
                // Encontrar todos os anúncios na página
                const adElements = document.querySelectorAll('.adsbygoogle');
                
                // Inicializar cada anúncio
                adElements.forEach(ad => {
                    if (!ad.dataset.adsbygoogleStatus) {
                        (adsbygoogle = window.adsbygoogle || []).push({});
                    }
                });
                
                console.log(`Initialized ${adElements.length} ad units`);
            } catch (e) {
                console.log('AdSense initialization error:', e);
            }
        }
        
        // Refresh anúncios após conversão bem-sucedida
        function refreshAdsAfterConversion() {
            setTimeout(() => {
                try {
                    const adElements = document.querySelectorAll('.adsbygoogle[data-ad-position="rectangle-post-converter"]');
                    adElements.forEach(ad => {
                        (adsbygoogle = window.adsbygoogle || []).push({});
                    });
                } catch (e) {
                    console.log('Ad refresh error:', e);
                }
            }, 2000);
        }
    </script>
}