<?php
// Include your database connection here
include 'connect.php';

if (isset($_GET['catID'])) {
  $catID = $_GET['catID'];

  // Assuming you have a database table named 'categories'
  $query = "SELECT * FROM categories WHERE CategoryID = $catID";
  $result = mysqli_query($con, $query);

  if ($result) {
    $row = mysqli_fetch_assoc($result);

    // Prepare and return the HTML content for the edit modal
    $categoryName = $row['CategoryName'];
    $categoryImage = $row['CategoryImage'];
    $categoryColor = $row['CategoryColor'];

    $editModalContent = '
      <div class="modal-header">
        <h5 class="modal-title" id="editCategoryModalLabel">Edit Category</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
        <form id="editCategoryForm">
          <div class="mb-3">
            <label for="editCategoryName" class="form-label">Category Name</label>
            <input type="text" class="form-control" id="editCategoryName" value="' . $categoryName . '">
          </div>
          <div class="mb-3">
            <label for="editImage" class="form-label">Category Image</label>
            <input type="file" class="form-control" id="editImage">
          </div>
          <div class="mb-3">
            <label for="editColor" class="form-label">Color</label>
            <input type="color" class="form-control" id="editColor" value="' . $categoryColor . '">
          </div>
        </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-success" id="saveEditCategoryButton">Save</button>
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
      </div>';

    echo $editModalContent;
  } else {
    // Handle the error, e.g., return an error message
    echo 'Error: Unable to fetch category details.';
  }
} else {
  // Handle the case where 'catID' is not provided
  echo 'Error: Category ID is missing.';
}
?>
