<?php
include("auth.php");
include("config/db.php");

/* =======================
   प्रशंसापत्र सहेजें (केवल छवि)
======================= */
if (isset($_POST['save'])) {

    if (empty($_FILES['image']['name'])) {
        die("छवि आवश्यक है");
    }

    $imageName = time() . '_' . basename($_FILES['image']['name']);
    $tmp       = $_FILES['image']['tmp_name'];

    move_uploaded_file($tmp, "uploads/testimonials/" . $imageName);

    mysqli_query(
        $conn,
        "INSERT INTO testimonials (image) VALUES ('$imageName')"
    );

    header("Location: testimonials.php");
    exit;
}
?>

<!DOCTYPE html>
<html lang="hi">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>प्रशंसापत्र छवि जोड़ें</title>

<link href="https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@300;400;600;700&display=swap" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons/font/bootstrap-icons.css" rel="stylesheet">

<style>
html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  font-family: 'Source Sans Pro', sans-serif;
  background: #f5f7fa;
}

* { box-sizing: border-box; }

/* FULL WIDTH MAIN */
.main {
  width: 100%;
  min-height: 100vh;
  padding: 30px;
}

/* CENTER CARD */
.card {
  max-width: 600px;
  margin: 0 auto;
}

/* MOBILE */
@media (max-width: 768px) {
  .main { padding: 15px; }

  .btn {
    width: 100%;
    margin-bottom: 10px;
  }
}
</style>
</head>

<body>

<div class="main">

  <div class="card shadow-sm">
    <div class="card-header bg-white">
      <h5 class="mb-0">➕ प्रशंसापत्र छवि जोड़ें</h5>
    </div>

    <div class="card-body">

      <form method="post" enctype="multipart/form-data">

        <!-- IMAGE ONLY -->
        <div class="mb-4">
          <label class="form-label fw-semibold">प्रशंसापत्र छवि</label>
          <input type="file"
                 name="image"
                 class="form-control form-control-lg"
                 required>
        </div>

        <div class="d-flex flex-wrap gap-2">
          <button type="submit"
                  name="save"
                  class="btn btn-success px-4">
            <i class="bi bi-check-circle"></i> सहेजें
          </button>

          <a href="testimonials.php"
             class="btn btn-secondary px-4">
            वापस जाएँ
          </a>
        </div>

      </form>

    </div>
  </div>

</div>

</body>
</html>
