// booking-modal.jsx — New Booking modal with 4 tabs const PAY_METHODS = [ { k: 'cash', l: 'Tiền mặt', ico: 'cash' }, { k: 'card', l: 'Thẻ', ico: 'card' }, { k: 'transfer', l: 'Chuyển khoản', ico: 'bank' }, { k: 'qr', l: 'QR', ico: 'qr' }, { k: 'pay_later', l: 'Trả sau', ico: 'later' }, ]; function NewBookingModal({ initialRoomId, initialDate, onClose, onSave }) { const data = window.HotelData; const [tab, setTab] = React.useState(0); const [completed, setCompleted] = React.useState(new Set()); // Form state const [form, setForm] = React.useState(() => { const ci = initialDate ? new Date(initialDate) : new Date(data.today); const co = new Date(ci); co.setDate(co.getDate() + 1); return { roomId: initialRoomId || 'r101', checkIn: ci, checkInTime: '14:00', checkOut: co, checkOutTime: '12:00', guests_count: 2, source: 'website', note: '', guestName: '', guestPhone: '', guestEmail: '', guestId: '', nationality: 'Việt Nam', returning: false, services: {}, // {svId: qty} paymentMethod: 'card', deposit: 0, discount: 0, }; }); const set = (k, v) => setForm(f => ({ ...f, [k]: v })); // Derived const room = findRoom(data.rooms, form.roomId); const nights = Math.max(1, daysBetween(form.checkIn, form.checkOut)); const roomTotal = room ? room.price * nights : 0; const servicesTotal = Object.entries(form.services).reduce((sum, [id, qty]) => { const sv = findService(data.serviceCatalog, id); return sum + (sv ? sv.price * qty : 0); }, 0); const subtotal = roomTotal + servicesTotal; const tax = Math.round(subtotal * 0.1); const discount = Number(form.discount) || 0; const total = Math.max(0, subtotal + tax - discount); // Tab nav const tabs = [ { l: 'Thông tin phòng', ico: 'bed' }, { l: 'Thông tin khách', ico: 'user' }, { l: 'Dịch vụ', ico: 'sparkle' }, { l: 'Thanh toán', ico: 'card' }, ]; const next = () => { const newCompleted = new Set(completed); newCompleted.add(tab); setCompleted(newCompleted); setTab(Math.min(3, tab + 1)); }; const prev = () => setTab(Math.max(0, tab - 1)); const handleSave = () => { const services = Object.entries(form.services) .filter(([_, q]) => q > 0) .map(([id, qty]) => ({ id, qty })); onSave({ id: 'BK-' + Math.floor(2500 + Math.random() * 99), code: 'SM' + Math.floor(2500 + Math.random() * 99), roomId: form.roomId, guestId: 'new-' + Date.now(), _newGuest: { name: form.guestName || 'Khách mới', phone: form.guestPhone, email: form.guestEmail, id_no: form.guestId, nationality: form.nationality, returning: false, stays: 1, }, checkIn: form.checkIn, checkOut: form.checkOut, checkInTime: form.checkInTime, checkOutTime: form.checkOutTime, guests_count: form.guests_count, status: form.source, paymentStatus: form.deposit >= total ? 'paid' : form.deposit > 0 ? 'partial' : 'unpaid', paid: Number(form.deposit) || 0, paymentMethod: form.paymentMethod, source: form.source === 'website' ? 'Website' : form.source === 'walkin' ? 'Tại chỗ' : form.source === 'pending' ? 'Điện thoại' : 'OTA', services, note: form.note, createdBy: 'Lễ tân Hà', checkedIn: false, }); }; return (