<?php

$lote_id = isset($_GET['id']) ? $_GET['id'] : '';

$qr_size = isset($_GET['qrSize']) ? intval($_GET['qrSize']) : 10;

$background_color = isset($_GET['background_color']) ? $_GET['background_color'] : '#e6e6e6';

$text_color = isset($_GET['text_color']) ? $_GET['text_color'] : '#000000';

$imprimir_codigo = isset($_GET['imprimir_codigo']) ? $_GET['imprimir_codigo'] : '';

if($lote_id!=''){

    include('../../path.php');

    require_once(ROOT_CONTROLLER.'lote_qr.php');

    $Obj_lote_qr = new lote_qr();

    $Obj_lote_qr->impreso($lote_id);

}

?>

<!DOCTYPE html>

<html lang="es">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Ver PDF</title>

    <style>

        body {

            font-family: Arial, sans-serif;

            margin: 0;

            padding: 0;

        }

        #pdfContainer {

            position: relative;

            width: 100%;

            height: 100vh;

            background-color: #f0f0f0;

        }

        iframe {

            width: 100%;

            height: calc(100vh - 50px); /* Ajusta la altura del iframe */

            border: none;

        }

        .back-button {

            position: relative;

            padding: 10px 20px;

            background-color: #ff1100;

            color: white;

            border: none;

            border-radius: 5px;

            cursor: pointer;

        }

    </style>

</head>

<body>

    <div id="pdfContainer">

        <button class="back-button" onclick="loadingpage();window.location.href='index'">Volver Atrás</button>

        <br><br>

        <iframe id="pdfIframe" src="" style="width:100%;height:80vh;"></iframe>

    </div>



    <script>

        // Obtener el parámetro 'id' y 'qrSize' de la URL y establecer el src del iframe

        /*const urlParams = new URLSearchParams(window.location.search);

        const id = urlParams.get('id');

        const qrSize = urlParams.get('qrSize');*/

        /*if(<?=$qr_size;?>==1){

            const pdfUrl = '../bussines/preset1.php?id=<?=$lote_id?>&qrSize=<?=$qr_size?>&background_color=' + encodeURIComponent(<?= json_encode($background_color) ?>) + '&text_color=' + encodeURIComponent(<?= json_encode($text_color) ?>) + '&imprimir_codigo=<?=$imprimir_codigo?>';

            document.getElementById('pdfIframe').src = pdfUrl;

        }else if(<?=$qr_size;?>==3){

            const pdfUrl = '../bussines/preset3.php?id=<?=$lote_id?>&qrSize=<?=$qr_size?>&background_color=' + encodeURIComponent(<?= json_encode($background_color) ?>) + '&text_color=' + encodeURIComponent(<?= json_encode($text_color) ?>) + '&imprimir_codigo=<?=$imprimir_codigo?>';

            document.getElementById('pdfIframe').src = pdfUrl;

        }else if(<?=$qr_size;?>==5){

            const pdfUrl = '../bussines/preset5.php?id=<?=$lote_id?>&qrSize=<?=$qr_size?>&background_color=' + encodeURIComponent(<?= json_encode($background_color) ?>) + '&text_color=' + encodeURIComponent(<?= json_encode($text_color) ?>) + '&imprimir_codigo=<?=$imprimir_codigo?>';

            document.getElementById('pdfIframe').src = pdfUrl;

        }else{

            const pdfUrl = '../bussines/preset10.php?id=<?=$lote_id?>&qrSize=<?=$qr_size?>&background_color=' + encodeURIComponent(<?= json_encode($background_color) ?>) + '&text_color=' + encodeURIComponent(<?= json_encode($text_color) ?>) + '&imprimir_codigo=<?=$imprimir_codigo?>';

            document.getElementById('pdfIframe').src = pdfUrl;

        }*/

            //const pdfUrl = '../bussines/generate_pdf.php?id=<?=$lote_id?>&qrSize=<?=$qr_size?>&background_color=' + encodeURIComponent(<?= json_encode($background_color) ?>) + '&text_color=' + encodeURIComponent(<?= json_encode($text_color) ?>) + '&imprimir_codigo=<?=$imprimir_codigo?>';

            const pdfUrl = '../bussines/QR_PDF.php?id=<?=$lote_id?>&qrSize=<?=$qr_size?>&background_color=' + encodeURIComponent(<?= json_encode($background_color) ?>) + '&text_color=' + encodeURIComponent(<?= json_encode($text_color) ?>) + '&imprimir_codigo=<?=$imprimir_codigo?>';

            document.getElementById('pdfIframe').src = pdfUrl;

        

    </script>

    <script>

        window.onload=function(){

            if(parent.document.getElementById('loadingpage')){

                parent.document.getElementById('loadingpage').style.display='none';

            }

        }

        

        function loadingpage(){

            if(parent.document.getElementById('loadingpage')){

              parent.document.getElementById('loadingpage').style.display='block'; 

            }

        }

    </script>

</body>

</html>