<?php

$pageTitle =
    'Sửa Gallery - PET SPA';

$pageStyles = [
    'owner.css'
];

$activeOwnerPage =
    'gallery';


$successMessage =
    $_SESSION['flash_success']
    ?? null;

$errorMessage =
    $_SESSION['flash_error']
    ?? null;


unset(
    $_SESSION['flash_success'],
    $_SESSION['flash_error']
);


require BASE_PATH
    . '/app/views/layouts/header.php';

require BASE_PATH
    . '/app/views/layouts/navbar.php';

?>

<main class="owner-area">

<div class="container-fluid">

<div class="row g-4">

<div class="col-xl-2 col-lg-3">

<?php require BASE_PATH
    . '/app/views/layouts/owner-sidebar.php';
?>

</div>


<div class="col-xl-10 col-lg-9">

<div class="owner-page-header">

<div>

<a
    href="<?= BASE_URL ?>/?url=owner/gallery"
    class="small text-decoration-none"
>
    ← Gallery
</a>

<h1 class="mt-2">
    Chỉnh sửa hình ảnh
</h1>

</div>

</div>


<?php if ($successMessage): ?>

<div class="alert alert-success">

<?= htmlspecialchars(
    $successMessage
) ?>

</div>

<?php endif; ?>


<?php if ($errorMessage): ?>

<div class="alert alert-danger">

<?= htmlspecialchars(
    $errorMessage
) ?>

</div>

<?php endif; ?>


<form
    method="POST"
    action="<?= BASE_URL ?>/?url=owner/gallery/update"
>

<input
    type="hidden"
    name="_token"
    value="<?= htmlspecialchars(
        $_SESSION['csrf_token']
    ) ?>"
>

<input
    type="hidden"
    name="gallery_id"
    value="<?= (int)
        $item['id']
    ?>"
>


<div class="row g-4">

<div class="col-lg-5">

<section class="owner-card">

<img
    src="<?= BASE_URL ?>/<?= htmlspecialchars(
        ltrim(
            $item['image_path'],
            '/'
        )
    ) ?>"
    class="img-fluid rounded"
    alt=""
>

</section>

</div>


<div class="col-lg-7">

<section class="owner-card">

<h2>
    Thông tin
</h2>


<div class="mb-3">

<label class="form-label">
    Tiêu đề
</label>

<input
    type="text"
    name="title"
    class="form-control"
    value="<?= htmlspecialchars(
        $item['title']
        ?? ''
    ) ?>"
>

</div>


<div class="mb-3">

<label class="form-label">
    Danh mục
</label>

<input
    type="text"
    name="category"
    class="form-control"
    value="<?= htmlspecialchars(
        $item['category']
        ?? ''
    ) ?>"
>

</div>


<div class="mb-3">

<label class="form-label">
    Mô tả
</label>

<textarea
    name="caption"
    class="form-control"
    rows="4"
><?= htmlspecialchars(
    $item['caption']
    ?? ''
) ?></textarea>

</div>


<div class="mb-3">

<label class="form-label">
    Thứ tự
</label>

<input
    type="number"
    name="sort_order"
    class="form-control"
    value="<?= (int)
        $item['sort_order']
    ?>"
>

</div>


<div class="form-check">

<input
    type="checkbox"
    name="is_visible"
    class="form-check-input"
    id="editGalleryVisible"
    <?= (int)
        $item['is_visible'] === 1
        ? 'checked'
        : ''
    ?>
>

<label
    class="form-check-label"
    for="editGalleryVisible"
>
    Hiển thị trên website
</label>

</div>


<button
    class="btn btn-primary mt-4"
    type="submit"
>
    Lưu thay đổi
</button>

</section>

</div>

</div>

</form>

</div>

</div>

</div>

</main>


<?php

require BASE_PATH
    . '/app/views/layouts/footer.php';

?>