<?php $pageTitle = 'Đặt lịch Spa - PET SPA'; $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="container py-5"><h1>Đặt lịch Spa</h1><?php if ($errorMessage): ?><div class="alert alert-danger"><?= htmlspecialchars($errorMessage) ?></div><?php endif; ?><form class="row g-3" method="post" action="<?= BASE_URL ?>/?url=customer/booking/store"><input type="hidden" name="_token" value="<?= htmlspecialchars($_SESSION['csrf_token'] ?? '') ?>"><div class="col-md-6"><label class="form-label">Dịch vụ</label><select id="service" class="form-select" name="service_id" required><option value="">Chọn dịch vụ</option><?php foreach ($services as $item): ?><option value="<?= (int) $item['id'] ?>" <?= $service && (int) $service['id'] === (int) $item['id'] ? 'selected' : '' ?>><?= htmlspecialchars($item['name']) ?> — <?= (int) $item['duration_minutes'] ?> phút</option><?php endforeach; ?></select></div><div class="col-md-3"><label class="form-label">Ngày</label><input id="date" class="form-control" type="date" min="<?= date('Y-m-d') ?>" name="booking_date" required></div><div class="col-md-3"><label class="form-label">Khung giờ</label><select id="slot" class="form-select" name="start_time" required><option value="">Chọn ngày trước</option></select></div><div class="col-md-4"><label class="form-label">Tên thú cưng</label><input class="form-control" name="pet_name" maxlength="120" required></div><div class="col-md-3"><label class="form-label">Loài</label><select class="form-select" name="pet_type" required><option value="dog">Chó</option><option value="cat">Mèo</option><option value="other">Khác</option></select></div><div class="col-md-3"><label class="form-label">Giống</label><input class="form-control" name="pet_breed" maxlength="120"></div><div class="col-md-2"><label class="form-label">Cân nặng (kg)</label><input class="form-control" name="pet_weight" type="number" min="0.01" max="9999.99" step="0.01"></div><div class="col-12"><label class="form-label">Lưu ý cho Spa</label><textarea class="form-control" name="pet_notes" maxlength="1000" rows="2"></textarea></div><div class="col-12"><label class="form-label">Ghi chú lịch hẹn</label><textarea class="form-control" name="notes" maxlength="1000" rows="2"></textarea></div><div><button class="btn btn-primary">Gửi yêu cầu đặt lịch</button></div></form></main>
<script>const s=document.getElementById('service'),d=document.getElementById('date'),o=document.getElementById('slot');async function slots(){o.innerHTML='<option>Đang tải…</option>';if(!s.value||!d.value)return;o.innerHTML='';try{let r=await fetch('<?= BASE_URL ?>/?url=customer/booking/available-slots&service_id='+encodeURIComponent(s.value)+'&date='+encodeURIComponent(d.value)),j=await r.json();o.innerHTML='<option value="">Chọn giờ</option>'+(j.slots||[]).map(x=>'<option value="'+x+'">'+x+'</option>').join('');}catch(e){o.innerHTML='<option>Không tải được slot</option>';}}s.addEventListener('change',slots);d.addEventListener('change',slots);</script>
<?php require BASE_PATH . '/app/views/layouts/footer.php'; ?>
