<?php
require_once "../config/auth.php";
require_once "../config/db.php";
require_once "../config/helpers.php";

require_once "../includes/header.php";
require_once "../includes/sidebar.php";
require_once "../includes/topbar.php";

$id = (int) ($_GET['id'] ?? 0);

$expense = $conn->query("SELECT * FROM expenses WHERE id=$id")->fetch_assoc();

if(!$expense){
    die("Expense not found");
}
?>

<div class="main-content">
<div class="col-lg-12">

<div class="topbar">
    <h5>Edit Expense</h5>
</div>

<div class="p-4">

<form method="POST" action="../actions/update_expense.php">

<input type="hidden" name="id" value="<?= $expense['id'] ?>">

<div class="mb-3">
<label>Title *</label>
<input type="text" name="title" class="form-control"
value="<?= e($expense['title']) ?>" required>
</div>

<div class="mb-3">
<label>Amount *</label>
<input type="number" name="amount" class="form-control"
value="<?= $expense['amount'] ?>" step="0.01" required>
</div>

<div class="mb-3">
<label>Date *</label>
<input type="date" name="expense_date" class="form-control"
value="<?= $expense['expense_date'] ?>" required>
</div>

<button class="btn btn-primary">Update Expense</button>

</form>

</div>
</div>
</div>

<?php require_once "../includes/footer.php"; ?>
