<?php

include('php/database.php');
include('php/security.php');
session_start();
if (logged_in()) {
    header('location:../login.php');
}
$id = $_SESSION['id'];
$results = mysqli_query($connection, "SELECT `date`, `id`, `name`, `email`, `number`, `password`, `phone`, `address`, `country`, `gender`, `image`, `vcode`, `verified`, `verify`, `balance`, `totalbalance`, `investbalance`, `profit`, `totaldeposit`, `totalwithdrawal`, `loanlimit`, `availableloan`, `ongoingloan`, `savings`, `idcard`, `idcardback`, `accountstatus`, `pina`, `pinb`, `pinc`, `pind` FROM users WHERE id ='$id'");
$retrive = mysqli_fetch_array($results);
$date = $retrive['date'];
$id = $retrive['id'];
$name = $retrive['name'];
$email = $retrive['email'];
$number = $retrive['number'];
$password = $retrive['password'];
$phone = $retrive['phone'];
$address = $retrive['address'];
$country = $retrive['country'];
$gender = $retrive['gender'];
$image = $retrive['image'];
$vcode = $retrive['vcode'];
$verified = $retrive['verified'];
$verify = $retrive['verify'];
$balance = $retrive['balance'];
$totalbalance = $retrive['totalbalance'];
$investbalance = $retrive['investbalance'];
$profit = $retrive['profit'];
$totaldeposit = $retrive['totaldeposit'];
$totalwithdrawal = $retrive['totalwithdrawal'];
$loanlimit = $retrive['loanlimit'];
$availableloan = $retrive['availableloan'];
$ongoingloan = $retrive['ongoingloan'];
$savings = $retrive['savings'];
$idcard = $retrive['idcard'];
$idcardback = $retrive['idcardback'];
$accountstatus = $retrive['accountstatus'];
$pina = $retrive['pina'];
$pinb = $retrive['pinb'];
$pinc = $retrive['pinc'];
$pind = $retrive['pind'];

if (isset($_GET['tid'])) {

    $tid = $_GET['tid'];
} else {
    header('location:index.php');
}
$item_query = "SELECT * FROM `transactions` WHERE tid='$tid'";
$item_query_run = mysqli_query($connection, $item_query);

if (mysqli_num_rows($item_query_run) > 0) {
    while ($itemrow = mysqli_fetch_assoc($item_query_run)) {

        $tdate = new DateTime($itemrow['date']);
        $nicetime = $tdate->format("j F Y");

        if ($itemrow['status'] == 'Completed') {

            $badge = "blue";
        }
        if ($itemrow['status'] == 'Pending') {

            $badge = "yellow";
        }
        if ($itemrow['status'] == 'Failed') {

            $badge = "red";
        }




        ?>



        <!DOCTYPE html>
        <html lang="en">


        <head>
            <meta charset="UTF-8">
            <meta http-equiv="X-UA-Compatible" content="IE=edge">
            <!-- Mobile Specific Metas -->
            <meta name="viewport" content="width=device-width, initial-scale=0.7, viewport-fit=cover">
            <title>Transaction Details</title>
            <!-- Favicon and Touch Icons  -->
            <link rel="shortcut icon" href="images/logo.png" />
            <link rel="apple-touch-icon-precomposed" href="images/logo.png" />
            <!-- Font -->
            <link rel="stylesheet" href="fonts/fonts.css" />
            <!-- Icons -->
            <link rel="stylesheet" href="fonts/icons-alipay.css">
            <link rel="stylesheet" href="styles/bootstrap.css">

            <link rel="stylesheet" type="text/css" href="styles/styles.css" />
            <link rel="manifest" href="_manifest.json" data-pwa-version="set_in_manifest_and_pwa_js">
            <link rel="apple-touch-icon" sizes="192x192" href="app/icons/icon-192x192.png">
            <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js "></script>
            <script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js"></script>

            <script src="https://cdn.tailwindcss.com"></script>
        </head>

        <body class="bg-gray-100 min-h-screen">
            <!-- Header -->
            <header class="bg-blue-300 text-white py-6 px-8 text-2xl font-semibold">
                Transaction Details &nbsp; &nbsp;
            </header>

            <!-- Transaction Summary -->
            <section class="max-w-4xl mx-auto py-8 px-6 space-y-6">
                <div class="bg-white shadow-md rounded-lg p-6">
                    <h2 class="text-xl font-semibold text-gray-800"><?php echo $itemrow['type']; ?></h2>
                    <p class="text-sm text-gray-500"><?php echo $nicetime; ?></p>
                    <div class="mt-4 flex justify-between items-center">
                        <span
                            class="text-lg font-semibold text-<?php echo $itemrow['color']; ?>-500"><?php echo $itemrow['sign']; ?>$<?php echo $itemrow['amount']; ?></span>
                        <span
                            class="px-3 py-1 bg-<?php echo $badge; ?>-500 text-white text-xs rounded-full"><?php echo $itemrow['status']; ?></span>
                    </div>
                </div>

                <!-- Transaction Details -->
                <div class="bg-white shadow-md rounded-lg p-6 space-y-4">
                    <div class="flex justify-between text-gray-700">
                        <span>Transaction ID:</span>
                        <span class="font-medium"><?php echo $itemrow['tid']; ?></span>
                    </div>
                    <div class="flex justify-between text-gray-700">
                        <span>Transaction Type:</span>
                        <span class="font-medium"><?php echo $itemrow['type']; ?></span>
                    </div>
                    <div class="flex justify-between text-gray-700">
                        <span>Sender:</span>
                        <span class="font-medium"><?php echo $itemrow['from']; ?></span>
                    </div>
                    <div class="flex justify-between text-gray-700">
                        <span>Receiver:</span>
                        <span class="font-medium"><?php echo $itemrow['to']; ?></span>
                    </div>
                    <div class="flex justify-between text-gray-700">
                        <span>Status:</span>
                        <span class="font-medium text-<?php echo $badge; ?>-500"><?php echo $itemrow['status']; ?></span>
                    </div>
                </div>
            </section>

            <!-- Footer Buttons -->
            <footer class="bg-gray-50 py-6 px-8 flex justify-between">
                <a href="javascript:history.back()"
                    class="px-4 py-2 bg-gray-300 text-gray-800 rounded-lg hover:bg-gray-400 transition">Back</a>
                <div class="gtranslate_wrapper"></div>
                <script>window.gtranslateSettings = { "default_language": "en", "detect_browser_language": true, "wrapper_selector": ".gtranslate_wrapper" }</script>
                <script src="https://cdn.gtranslate.net/widgets/latest/dropdown.js" defer></script>
            </footer>

            <script>
                window.jsPDF = window.jspdf.jsPDF;
                var docPDF = new jsPDF();

                function downloadPDF(invoiceNo) {

                    var elementHTML = document.querySelector("#myBillingArea");
                    docPDF.html(elementHTML, {
                        callback: function (docPDF) {
                            docPDF.save(invoiceNo + '.pdf');
                        },
                        x: 15,
                        y: 15,
                        width: 170,
                        windowWidth: 650
                    });
                }


            </script>

        </body>


        </html>

        <?php
    }
}

?>