<?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";

$customers = $conn->query("SELECT id,name FROM customers");
?>

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

<div class="topbar">
    <h5>Add Service</h5>
</div>

<div class="p-4">

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

<!-- CUSTOMER -->
<div class="mb-3">
<label>Customer *</label>
<select name="customer_id" class="form-control" required>
<option value="">Select</option>
<?php while($c = $customers->fetch_assoc()){ ?>
<option value="<?= $c['id'] ?>"><?= e($c['name']) ?></option>
<?php } ?>
</select>
</div>

<!-- SERVICE NAME -->
<div class="mb-3">
<label>Service Name *</label>
<input type="text" name="service_name" class="form-control"
placeholder="Eg: Hosting - example.com (1 Year)" required>
</div>

<!-- TYPE -->
<div class="mb-3">
<label>Type *</label>
<select name="type" class="form-control" required>
<option value="domain">Domain</option>
<option value="hosting">Hosting</option>
<option value="amc">AMC</option>
<option value="other">Other</option>
</select>
</div>

<!-- AMOUNT -->
<div class="mb-3">
<label>Amount *</label>
<input type="number" name="amount" class="form-control" required>
</div>

<!-- COST -->
<div class="mb-3">
<label>Cost (Optional)</label>
<input type="number" name="cost" class="form-control">
</div>

<!-- START DATE -->
<div class="mb-3">
<label>Start Date *</label>
<input type="date" name="start_date" class="form-control"
value="<?= date('Y-m-d') ?>" required>
</div>

<!-- RENEWAL -->
<div class="mb-3">
<label>Renewal Date *</label>
<input type="date" name="renewal_date" class="form-control" required>
</div>

<button class="btn btn-primary">Save Service</button>

</form>

</div>
</div>
</div>
<?php if(isset($_GET['success'])){ ?>
<div id="successToast" class="toast align-items-center text-bg-success border-0 position-fixed top-0 end-0 m-3" role="alert">
  <div class="d-flex">
    <div class="toast-body">
      Service added successfully!
    </div>
    <button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast"></button>
  </div>
</div>
<?php } ?>
<?php require_once "../includes/footer.php"; ?>
