<?php
// Arrays empfangen und dekodieren
$bibliographicArray 	= json_decode($_POST['bibliograpicArray'] ?? '[]', true);
$identificatorArray	= json_decode($_POST['identificatorArray'] ?? '[]', true);
$typeArray 	   	= json_decode($_POST['typeArray'] ?? '[]', true);
$subjectArray		= json_decode($_POST['subjectArray'] ?? '[]', true);
$contractArray		= json_decode($_POST['contractArray'] ?? '[]', true);

include "prepareBibliographicSummary.php" ;      
include "prepareIdentificatorSummary.php" ;
include "prepareSubjectSummary.php"; 
include "prepareTypeSummary.php"; 
include "prepareContractSummary.php";
include "prepareBibliographicSummaryStripped.php"; 
$resArrayBibliographic = json_encode($resArrayBibliographic) ;
?>
<!DOCTYPE html>
<html lang="de">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Zusammenfassung</title>
    
    <!-- Bootstrap 5 CSS && Bootstrap Icons -->
    <?php include "include/includeJSandCSS.php" ?>

    <!-- Custom CSS -->
    <link href="css/bibb.css" media="all" rel="stylesheet" type="text/css">
    
    <style>
        .modal {
            display: none;
            position: fixed;
            z-index: 1050;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            overflow: auto;
            background-color: rgba(0,0,0,0.4);
        }
        
        .modal-content {
            background-color: #fefefe;
            margin: 15% auto;
            padding: 20px;
            border: 1px solid #888;
            border-radius: 0.375rem;
            width: 80%;
            max-width: 600px;
        }
        
        .modal-buttons {
            text-align: right;
            margin-top: 20px;
        }
        
        .btn-correct, .btn-publish {
            margin-left: 10px;
            padding: 8px 16px;
            border: none;
            border-radius: 0.375rem;
            cursor: pointer;
        }
        
        .btn-correct {
            background-color: #6c757d;
            color: white;
        }
        
        .btn-publish {
            background-color: #198754;
            color: white;
        }
        
        .btn-correct:hover {
            background-color: #5a6268;
        }
        
        .btn-publish:hover {
            background-color: #157347;
        }
    </style>
</head>

<body>
    <header class="d-print-none">
        <?php include "templates/headerLogout.php" ?>
    </header>
    
    <div class="container-fluid">
        <h4 class="ps-5" style="text-decoration: underline;">Zusammenfassung</h4>
        <div class="ps-5 pe-5">
            <p><?= $bibliographicDataHTML ?></p>
            <p><?= $identificatorDataHTML ?></p>
            <p><?= $typeDataHTML ?></p>
            <p><?= $subjectDataHTML ?></p>
            <p><?= $contractDataHTML ?></p>
        </div>
        
        <!--
        <h2>Hochgeladene Dokumente</h2> 
        -->
        
        <script> 
            var bibliographicArray = <?php echo json_encode($resArrayBibliographic) ?>; 
            var identificatorArray = <?php echo json_encode($identificatorArray) ?>;
            var typeArray = <?php echo json_encode($typeArray) ?>;
            var subjectArray = <?php echo json_encode($subjectArray) ?>;
            var contractArray = <?php echo json_encode($contractArray) ?>;
        </script>
        
        <!-- Bestätigen und zum Mailversand 
        <div class="d-grid pe-5 d-md-flex justify-content-md-end">
            <button type="submit" class="btn btn-bibb-success" onclick="sendFinalMail(bibliographicArray, identificatorArray, typeArray, subjectArray, contractArray)">Bestätigen und Vorgang abschicken</button>
        </div>
        -->
        
        <div class="d-grid pe-5 d-md-flex justify-content-md-end">
            <form action="checkModal.php" method="post">
                <button type="submit" class="btn btn-success">Bibliografische Daten anzeigen</button>
            </form>
        </div>
        
        <!-- Modal -->
        <div id="arrayModal" class="modal">
            <div class="modal-content">
                <div id="modalBody">
                    <!-- Arrays werden hier angezeigt -->
                </div>
                <div class="modal-buttons">
                    <button class="btn-correct" onclick="correctData()">Angaben korrigieren</button>
                    <button class="btn-publish" onclick="finishPublication()">Publikation abschließen</button>
                </div>
            </div>
        </div>
        
        <!-- <button onclick="history.back()">Zurück</button> -->
    </div>
    
    <?php include "templates/footer.php" ?>
    
</body>
</html>
