<?php
declare(strict_types=1);

/* ================= AUTH ================= */
require_once __DIR__ . '/../security/auth_guard_web.php';
require_once __DIR__ . '/../partials/main.php';
require_once __DIR__ . '/../config/database.php';

/* ================= VALIDATION ================= */
$id = (int) ($_GET['id'] ?? 0);
if ($id <= 0) {
    header('Location: index.php');
    exit;
}

$db = Database::getInstance();
$stmt = $db->prepare("SELECT * FROM hospitality_products WHERE id = :id");
$stmt->execute(['id' => $id]);
$product = $stmt->fetch(PDO::FETCH_ASSOC);

if (!$product) {
    header('Location: index.php');
    exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<?php includeFileWithVariables('../partials/title-meta.php', ['title' => 'View Hospitality Product']); ?>
<?php include '../partials/head-css.php'; ?>

<style>
.media-box{
    aspect-ratio:4/3;
    border:1px solid #dee2e6;
    border-radius:.5rem;
    background:#f8f9fa;
    overflow:hidden;
}
.media-box img{
    width:100%;
    height:100%;
    object-fit:cover;
}
.label-muted{
    font-size:.85rem;
    color:#6c757d;
}
</style>
</head>

<body>
<div id="layout-wrapper">

<?php include '../partials/header.php'; ?>
<?php include '../partials/sidebar.php'; ?>
<?php include '../partials/horizontal.php'; ?>

<main class="app-wrapper">
<div class="container-fluid">

<?php includeFileWithVariables('../partials/page-title.php', [
    'title_sub' => 'Hospitality',
    'title'     => 'View Hospitality Product'
]); ?>

<!-- ================= IMAGES ROW ================= -->
<div class="row g-4 mb-4">

<div class="col-md-4">
<div class="card shadow-sm">
<div class="card-header"><strong>Cover Image</strong></div>
<div class="card-body">
<div class="media-box">
<?php if ($product['cover_image']): ?>
<img src="<?= $product['cover_image'] ?>">
<?php else: ?><div class="text-muted p-3 text-center">No Image</div><?php endif; ?>
</div>
</div>
</div>
</div>

<div class="col-md-4">
<div class="card shadow-sm">
<div class="card-header"><strong>Banner (Desktop)</strong></div>
<div class="card-body">
<div class="media-box">
<?php if ($product['banner_image_desktop']): ?>
<img src="<?= $product['banner_image_desktop'] ?>">
<?php else: ?><div class="text-muted p-3 text-center">No Image</div><?php endif; ?>
</div>
</div>
</div>
</div>

<div class="col-md-4">
<div class="card shadow-sm">
<div class="card-header"><strong>Banner (Mobile)</strong></div>
<div class="card-body">
<div class="media-box">
<?php if ($product['banner_image_mobile']): ?>
<img src="<?= $product['banner_image_mobile'] ?>">
<?php else: ?><div class="text-muted p-3 text-center">No Image</div><?php endif; ?>
</div>
</div>
</div>
</div>

</div>

<!-- ================= PRODUCT DETAILS ================= -->
<div class="card shadow-sm mb-4">
<div class="card-header"><strong>Product Details</strong></div>
<div class="card-body">

<div class="row g-3">
<div class="col-md-6">
<p class="label-muted mb-1">Title</p>
<p class="fw-semibold"><?= htmlspecialchars($product['title']) ?></p>
</div>

<div class="col-md-6">
<p class="label-muted mb-1">Slug</p>
<code><?= htmlspecialchars($product['slug']) ?></code>
</div>

<div class="col-md-6">
<p class="label-muted mb-1">Product Type</p>
<p><?= $product['product_type'] ?></p>
</div>

<div class="col-md-6">
<p class="label-muted mb-1">Usage Category</p>
<p><?= $product['usage_category'] ?: '-' ?></p>
</div>

<div class="col-12">
<p class="label-muted mb-1">Short Description</p>
<p><?= nl2br(htmlspecialchars($product['short_description'])) ?: '-' ?></p>
</div>

<div class="col-12">
<p class="label-muted mb-1">Full Description</p>
<div class="border rounded p-3 bg-light">
<?= $product['description'] ?: '-' ?>
</div>
</div>

<div class="col-md-3">
<p class="label-muted mb-1">Priority</p>
<p><?= (int)$product['priority'] ?></p>
</div>

<div class="col-md-3">
<p class="label-muted mb-1">Status</p>
<span class="badge bg-<?= $product['status']==='Active'?'success':'secondary' ?>">
<?= $product['status'] ?>
</span>
</div>

<div class="col-md-3">
<p class="label-muted mb-1">Approval</p>
<span class="badge bg-<?= $product['approval_status']==='Approved'?'success':'warning' ?>">
<?= $product['approval_status'] ?>
</span>
</div>
</div>

</div>
</div>

<!-- ================= SEO DETAILS ================= -->
<div class="card shadow-sm mb-4">
<div class="card-header"><strong>SEO Details</strong></div>
<div class="card-body">

<div class="row g-3">
<div class="col-md-6">
<p class="label-muted mb-1">Meta Title</p>
<p><?= $product['meta_title'] ?: '-' ?></p>
</div>

<div class="col-md-6">
<p class="label-muted mb-1">Canonical URL</p>
<p><?= $product['canonical_url'] ?: '-' ?></p>
</div>

<div class="col-12">
<p class="label-muted mb-1">Meta Description</p>
<p><?= $product['meta_description'] ?: '-' ?></p>
</div>

<div class="col-12">
<p class="label-muted mb-1">Schema JSON</p>
<pre class="bg-light p-3 rounded small"><?= htmlspecialchars($product['schema_json']) ?: '-' ?></pre>
</div>
</div>

</div>
</div>

<!-- ================= ACTIONS ================= -->
<div class="card">
<div class="card-body d-flex justify-content-between">
<a href="index.php" class="btn btn-light">Back</a>
<a href="edit.php?id=<?= $product['id'] ?>" class="btn btn-warning">
<i class="bi bi-pencil-square me-1"></i> Edit Product
</a>
</div>
</div>

</div>
</main>

<?php include '../partials/footer.php'; ?>
</div>

<?php include '../partials/vendor-scripts.php'; ?>
</body>
</html>
