<?php
declare(strict_types=1);

require_once __DIR__ . "/functions.php";


$client = strtolower(
    trim($_GET['client'] ?? '')
);

$packageId = trim(
    $_GET['package'] ?? ''
);


if (!$client || !$packageId) {
    die("Data tidak lengkap.");
}


$subscription = getSubscription($client);


if (!$subscription) {
    die("Client tidak ditemukan.");
}


$packages = getPackages();


$package = null;


foreach ($packages as $p){

    if (($p['id'] ?? '') === $packageId){

        $package = $p;
        break;
    }
}


if (!$package){

    die("Paket tidak ditemukan.");

}


?>
<!doctype html>
<html lang="id">

<head>

<meta charset="utf-8">

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

<title>
Konfirmasi Perpanjangan
</title>


<style>

body{

margin:0;

background:#f8fafc;

font-family:
Arial,sans-serif;

color:#1e293b;

}


.container{

max-width:600px;

margin:50px auto;

padding:20px;

}


.card{

background:white;

border:1px solid #e5e7eb;

border-radius:16px;

padding:30px;

box-shadow:
0 10px 30px rgba(0,0,0,.05);

}


h1{

color:#7c3aed;

}


.row{

display:flex;

justify-content:space-between;

padding:12px 0;

border-bottom:1px solid #f1f5f9;

}


.label{

color:#64748b;

}


.value{

font-weight:600;

}


.total{

font-size:26px;

color:#7c3aed;

font-weight:bold;

margin-top:20px;

}


.button{

display:block;

margin-top:30px;

text-align:center;

background:#7c3aed;

color:white;

padding:14px;

border-radius:10px;

text-decoration:none;

font-weight:bold;

}


</style>

</head>


<body>


<div class="container">


<div class="card">


<h1>
Konfirmasi Pesanan
</h1>


<div class="row">

<div class="label">
Client
</div>

<div class="value">
<?=htmlspecialchars(strtoupper($subscription['client']))?>
</div>

</div>



<div class="row">

<div class="label">
Paket
</div>

<div class="value">
<?=htmlspecialchars($package['name'])?>
</div>

</div>



<div class="row">

<div class="label">
Masa Aktif
</div>

<div class="value">
<?=formatDuration($package['duration'])?>
</div>

</div>



<div class="row">

<div class="label">
Slot
</div>

<div class="value">
<?=$package['slots']?> User
</div>

</div>



<div class="total">

Rp <?=number_format((int)$package['price'],0,",",".")?>

</div>




<?php

require_once __DIR__ . "/order-function.php";

$orderId = createOrder(
    $client,
    $package['id'],
    (int)$package['price']
);

?>

<a class="button"
href="renew-payment.php?order=<?=urlencode($orderId)?>&client=<?=urlencode($client)?>">

Lanjut Pembayaran

</a>




</div>


</div>


</body>

</html>
