<?php
if(session_status() === PHP_SESSION_NONE) session_start();
require "../../config/config.php";
if(!defined("APPURL"))  define("APPURL",  "http://localhost/hotel-booking/");
if(!defined("ADMINURL")) define("ADMINURL", "http://localhost/hotel-booking/admin/");
if(!isset($_SESSION['admin_username'])){ header("location: " . ADMINURL . "login.php"); exit; }

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

// Get hotel image first
$hotel = $conn->prepare("SELECT image FROM hotels WHERE id = :id");
$hotel->execute([':id' => $id]);
$h = $hotel->fetch(PDO::FETCH_OBJ);

// Delete image file if it exists
if($h && $h->image && file_exists('../../images/' . $h->image)){
    unlink('../../images/' . $h->image);
}

// Delete from DB
$del = $conn->prepare("DELETE FROM hotels WHERE id = :id");
$del->execute([':id' => $id]);

header("location: index.php?success=Hotel deleted successfully");
exit;
