<?php
$pageTitle = ($service ? 'Sửa' : 'Thêm') . ' dịch vụ - PET SPA';
$pageStyles = ['owner.css'];
$activeOwnerPage = 'services';
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="owner-layout">
            <?php require BASE_PATH . '/app/views/layouts/owner-sidebar.php'; ?>

            <section class="owner-main">
                <div class="owner-page-header">
                    <div>
                        <h1><?= $service ? 'Sửa' : 'Thêm' ?> dịch vụ</h1>
                        <p>Thiết lập thông tin dịch vụ hiển thị cho khách hàng.</p>
                    </div>
                    <a class="btn btn-outline-secondary" href="<?= BASE_URL ?>/?url=owner/services">Quay lại</a>
                </div>

                <form class="owner-form-card" method="post" enctype="multipart/form-data" action="<?= BASE_URL ?>/?url=<?= $service ? 'owner/service/update' : 'owner/service/store' ?>">
                    <input type="hidden" name="_token" value="<?= htmlspecialchars($_SESSION['csrf_token'] ?? '') ?>">
                    <?php if ($service): ?><input type="hidden" name="service_id" value="<?= (int) $service['id'] ?>"><?php endif; ?>

                    <div class="row g-3">
                        <div class="col-md-6"><label class="form-label">Tên dịch vụ</label><input class="form-control" name="name" required value="<?= htmlspecialchars($service['name'] ?? '') ?>"></div>
                        <div class="col-md-3"><label class="form-label">Giá</label><input class="form-control" type="number" min="0" name="price" required value="<?= htmlspecialchars($service['price'] ?? '0') ?>"></div>
                        <div class="col-md-3"><label class="form-label">Thời lượng (phút)</label><input class="form-control" type="number" min="5" name="duration_minutes" required value="<?= htmlspecialchars($service['duration_minutes'] ?? '60') ?>"></div>
                        <div class="col-md-6"><label class="form-label">Danh mục</label><select class="form-select" name="category_id"><option value="0">Không phân loại</option><?php foreach ($categories as $item): ?><option value="<?= (int) $item['id'] ?>" <?= ($service['category_id'] ?? 0) == $item['id'] ? 'selected' : '' ?>><?= htmlspecialchars($item['name']) ?></option><?php endforeach; ?></select></div>
                        <div class="col-md-6"><label class="form-label">Ảnh</label><input class="form-control" type="file" name="featured_image" accept="image/jpeg,image/png,image/webp"></div>
                        <div class="col-12"><label class="form-label">Mô tả ngắn</label><input class="form-control" name="short_description" maxlength="500" value="<?= htmlspecialchars($service['short_description'] ?? '') ?>"></div>
                        <div class="col-12"><label class="form-label">Mô tả chi tiết</label><textarea class="form-control" name="description" rows="6"><?= htmlspecialchars($service['description'] ?? '') ?></textarea></div>
                        <div class="col-md-3"><label class="form-label">Thứ tự hiển thị</label><input class="form-control" type="number" name="sort_order" value="<?= htmlspecialchars($service['sort_order'] ?? '0') ?>"></div>
                        <div class="col-md-4 d-flex align-items-end"><div class="form-check mb-2"><input class="form-check-input" id="serviceActive" type="checkbox" name="is_active" <?= !$service || $service['is_active'] ? 'checked' : '' ?>><label class="form-check-label" for="serviceActive">Đang hiển thị</label></div></div>
                        <div class="col-12"><button class="btn btn-primary"><i class="bi bi-check-lg me-1"></i>Lưu dịch vụ</button></div>
                    </div>
                </form>
            </section>
        </div>
    </div>
</main>

<?php require BASE_PATH . '/app/views/layouts/footer.php'; ?>
