function fmt(n){ return n.toLocaleString("en-US"); } function flagEmoji(cc){ if (cc === "OTH") return "\u{1F3F3}\uFE0F"; return cc.toUpperCase().replace(/./g, ch => String.fromCodePoint(127397 + ch.charCodeAt(0)) ); } // ---------- nav toggle ---------- const navToggle = document.getElementById("navToggle"); const navLinks = document.getElementById("navLinks"); navToggle.addEventListener("click", () => { const isOpen = navLinks.classList.toggle("open"); navToggle.setAttribute("aria-expanded", String(isOpen)); }); navLinks.querySelectorAll("a").forEach(a => a.addEventListener("click", () => { navLinks.classList.remove("open"); navToggle.setAttribute("aria-expanded", "false"); })); // ---------- hero slideshow (JS crossfade + slow zoom, no gaps) ---------- (function(){ const slides = document.querySelectorAll(".hero-slide"); if (slides.length < 2) return; const PER = 6500; // time each image stays on screen const FADE = 1500; // crossfade duration let idx = 0; slides.forEach(s => { s.style.animation = "none"; s.style.transition = "none"; s.style.opacity = "0"; s.style.willChange = "opacity, transform"; }); // first image visible immediately, no fade-in, full 6.5s on screen slides[0].style.opacity = "1"; slides[0].style.transform = "scale(1.16)"; requestAnimationFrame(() => { slides.forEach(s => { s.style.transition = `opacity ${FADE}ms ease-in-out, transform ${PER}ms linear`; }); }); function show(i){ const s = slides[i]; s.style.opacity = "1"; s.style.transform = "scale(1.04)"; requestAnimationFrame(() => requestAnimationFrame(() => { s.style.transform = "scale(1.16)"; })); } setInterval(() => { const cur = slides[idx]; cur.style.opacity = "0"; cur.style.transform = "scale(1.04)"; idx = (idx + 1) % slides.length; show(idx); }, PER); })(); // ---------- country code select ---------- const countryCodeSelect = document.getElementById("countryCode"); COUNTRY_CODES.forEach(cc => { const opt = document.createElement("option"); opt.value = cc.dial; opt.textContent = `${flagEmoji(cc.c)} ${cc.dial} ${cc.name}`; if (cc.c === "ET") opt.selected = true; countryCodeSelect.appendChild(opt); }); // ---------- build room cards ---------- const roomsEl = document.getElementById("roomsGrid"); const roomTypeSelect = document.getElementById("roomType"); const placeholderOpt = document.createElement("option"); placeholderOpt.value = ""; placeholderOpt.textContent = "Select your room"; placeholderOpt.selected = true; placeholderOpt.disabled = true; roomTypeSelect.appendChild(placeholderOpt); ROOMS.forEach(room => { const card = document.createElement("div"); card.className = "room-card"; card.innerHTML = `
${room.images.map((src,i) => `${room.name}`).join("")}
${room.tag}
${room.images.map((_,i) => ``).join("")}

${room.name}

${room.desc}

${room.amenities.map(a=>`${a}`).join("")}
$${room.price} / night
`; roomsEl.appendChild(card); const opt = document.createElement("option"); opt.value = room.id; opt.textContent = `${room.name} — $${room.price}/night`; roomTypeSelect.appendChild(opt); // auto-sliding image carousel (motion, no clicks needed) const imgs = card.querySelectorAll(".slider-track img"); const dots = card.querySelectorAll(".dot"); let idx = 0; setInterval(() => { imgs[idx].classList.remove("active"); dots[idx].classList.remove("active"); idx = (idx + 1) % imgs.length; imgs[idx].classList.add("active"); dots[idx].classList.add("active"); }, 3200 + Math.random()*400); dots.forEach(d => d.addEventListener("click", (e) => { e.stopPropagation(); imgs[idx].classList.remove("active"); dots[idx].classList.remove("active"); idx = Number(d.dataset.i); imgs[idx].classList.add("active"); dots[idx].classList.add("active"); })); card.querySelector(".slider").addEventListener("click", () => openLightbox(room.id, idx)); card.querySelector("[data-book]").addEventListener("click", () => openModal(room.id)); }); // ---------- amenities ---------- const ICONS = { check: '', clock: '', home: '', droplet: '', coffee: '' }; function iconSvg(name){ return `${ICONS[name]}`; } const AMENITY_GROUPS = [ { title: "Complimentary services", icon: "check", items: ["Buffet breakfast", "Broadband internet & Wi-Fi", "Shuttle to/from Bole International Airport", "Gym and Spa access"] }, { title: "Front desk & services", icon: "clock", items: ["24-hour front desk", "Daily newspapers", "Elevator access", "Baggage storage"] }, { title: "In your room", icon: "home", items: ["Refrigerator", "Sofa", "Writing desk", "Telephone", "Suitcase rack", "Hair dryer", "Mini bar", "LED IP TV", "Safety box", "Cable TV", "Kettle", "Wardrobe"] }, { title: "Bathroom amenities", icon: "droplet", items: ["Shampoo", "Toothbrush & comb", "Body lotion", "Tub shower", "Water dispenser"] }, { title: "Tea & coffee corner", icon: "coffee", items: ["Tea", "Coffee", "Bottled water"] } ]; const amenitiesGrid = document.getElementById("amenitiesGrid"); AMENITY_GROUPS.forEach(group => { const card = document.createElement("div"); card.className = "amenity-card"; card.innerHTML = `
${iconSvg(group.icon)}

${group.title}

    ${group.items.map(i => `
  • ${i}
  • `).join("")}
`; amenitiesGrid.appendChild(card); }); // ---------- lightbox ---------- const lightbox = document.getElementById("lightbox"); const lightboxImg = document.getElementById("lightboxImg"); const lightboxThumbs = document.getElementById("lightboxThumbs"); const lightboxTitle = document.getElementById("lightboxTitle"); const lightboxDesc = document.getElementById("lightboxDesc"); const lightboxAmenities = document.getElementById("lightboxAmenities"); const lightboxPrice = document.getElementById("lightboxPrice"); const lightboxBookBtn = document.getElementById("lightboxBookBtn"); const lightboxPrev = document.getElementById("lightboxPrev"); const lightboxNext = document.getElementById("lightboxNext"); const lightboxClose = document.getElementById("lightboxClose"); const pageWrap = document.getElementById("pageWrap"); let lbRoom = null, lbIndex = 0; function renderLightbox(){ if (!lbRoom) return; lightboxImg.src = lbRoom.images[lbIndex]; lightboxImg.alt = `${lbRoom.name} — photo ${lbIndex + 1} of ${lbRoom.images.length}`; lightboxThumbs.querySelectorAll("button").forEach((t, i) => t.classList.toggle("active", i === lbIndex)); } function openLightbox(roomId, startIndex){ lbRoom = ROOMS.find(r => r.id === roomId); if (!lbRoom) return; lbIndex = startIndex || 0; lightboxTitle.textContent = lbRoom.name; lightboxDesc.textContent = lbRoom.desc; lightboxAmenities.innerHTML = lbRoom.amenities.map(a => `${a}`).join(""); lightboxPrice.innerHTML = `$${lbRoom.price} / night`; lightboxThumbs.innerHTML = lbRoom.images.map((src, i) => `` ).join(""); lightboxThumbs.querySelectorAll("button").forEach(t => t.addEventListener("click", () => { lbIndex = Number(t.dataset.i); renderLightbox(); }) ); renderLightbox(); lightbox.classList.add("open"); pageWrap.classList.add("blurred"); document.body.style.overflow = "hidden"; } function closeLightbox(){ lightbox.classList.remove("open"); pageWrap.classList.remove("blurred"); if (!overlay.classList.contains("open")) document.body.style.overflow = ""; lbRoom = null; } function lbStep(dir){ if (!lbRoom) return; lbIndex = (lbIndex + dir + lbRoom.images.length) % lbRoom.images.length; renderLightbox(); } lightboxPrev.addEventListener("click", () => lbStep(-1)); lightboxNext.addEventListener("click", () => lbStep(1)); lightboxClose.addEventListener("click", closeLightbox); lightbox.addEventListener("click", e => { if (e.target === lightbox) closeLightbox(); }); lightboxBookBtn.addEventListener("click", () => { const roomId = lbRoom ? lbRoom.id : null; closeLightbox(); if (roomId) openModal(roomId); }); document.addEventListener("keydown", e => { if (!lightbox.classList.contains("open")) return; if (e.key === "Escape") closeLightbox(); if (e.key === "ArrowLeft") lbStep(-1); if (e.key === "ArrowRight") lbStep(1); }); // ---------- modal ---------- const overlay = document.getElementById("overlay"); const bookingForm = document.getElementById("bookingForm"); const confirmView = document.getElementById("confirmView"); const confirmText = document.getElementById("confirmText"); const checkin = document.getElementById("checkin"); const checkout = document.getElementById("checkout"); const priceSummary = document.getElementById("priceSummary"); const nightsLine = document.getElementById("nightsLine"); const rateLine = document.getElementById("rateLine"); const totalLine = document.getElementById("totalLine"); const submitBtn = document.getElementById("submitBtn"); function openModal(roomId){ bookingForm.style.display = "flex"; confirmView.classList.remove("open"); bookingForm.reset(); countryCodeSelect.value = "+251"; priceSummary.classList.remove("show"); submitBtn.disabled = true; submitBtn.textContent = "Select dates to continue"; checkin.min = todayISO(); checkout.min = todayISO(); resetVoucher(); if (roomId) roomTypeSelect.value = roomId; overlay.classList.add("open"); document.body.style.overflow = "hidden"; updatePrice(); } document.getElementById("navBookBtn").addEventListener("click", () => openModal()); function closeModal(){ overlay.classList.remove("open"); document.body.style.overflow = ""; } document.getElementById("closeBtn").addEventListener("click", closeModal); document.getElementById("doneBtn").addEventListener("click", closeModal); overlay.addEventListener("click", e => { if (e.target === overlay) closeModal(); }); document.addEventListener("keydown", e => { if (e.key === "Escape" && overlay.classList.contains("open")) closeModal(); }); // ---------- native date pickers ---------- function todayISO(){ const d = new Date(); const m = String(d.getMonth() + 1).padStart(2, "0"); const dd = String(d.getDate()).padStart(2, "0"); return `${d.getFullYear()}-${m}-${dd}`; } function handleDateChange(){ if (checkin.value) { checkout.min = checkin.value; if (checkout.value && checkout.value <= checkin.value) { checkout.value = ""; priceSummary.classList.remove("show"); submitBtn.disabled = true; submitBtn.textContent = "Select check-out date"; } } updatePrice(); } checkin.addEventListener("change", handleDateChange); checkout.addEventListener("change", updatePrice); function updatePrice(){ const room = ROOMS.find(r => r.id === roomTypeSelect.value); const inDate = checkin.value, outDate = checkout.value; if (!inDate || !outDate || !room){ priceSummary.classList.remove("show"); submitBtn.disabled = true; submitBtn.textContent = "Select dates to continue"; return; } const nights = Math.round((new Date(outDate) - new Date(inDate)) / 86400000); if (nights <= 0){ priceSummary.classList.remove("show"); submitBtn.disabled = true; submitBtn.textContent = "Check-out must be after check-in"; return; } const total = nights * room.price; nightsLine.textContent = `${nights} night${nights>1?"s":""}`; rateLine.textContent = `$${room.price} / night`; totalLine.textContent = `$${fmt(total)}`; priceSummary.classList.add("show"); submitBtn.disabled = false; submitBtn.textContent = `Confirm booking — $${fmt(total)}`; } checkin.addEventListener("change", updatePrice); checkout.addEventListener("change", updatePrice); roomTypeSelect.addEventListener("change", updatePrice); const HOTEL_EMAIL = "reservation@thehubaddis.com"; const HOTEL_WHATSAPP = "251973545454"; const WEB3FORMS_ACCESS_KEY = "783dbe8b-06ea-4b36-bb87-3d60e4a121ad"; bookingForm.addEventListener("submit", e => { e.preventDefault(); const room = ROOMS.find(r => r.id === roomTypeSelect.value); const nights = Math.round((new Date(checkout.value) - new Date(checkin.value)) / 86400000); const total = nights * room.price; const firstName = document.getElementById("firstName").value; const middleName = document.getElementById("middleName").value; const lastName = document.getElementById("lastName").value; const fullName = [firstName, middleName, lastName].filter(Boolean).join(" "); const email = document.getElementById("email").value; const dial = countryCodeSelect.value; const phone = document.getElementById("phone").value; const notes = document.getElementById("notes").value; const paymentMethod = "Cash at check-in"; const summary = `Reservation request Name: ${fullName} Email: ${email} Phone: ${phone ? dial + " " + phone : "not provided"} Room: ${room.name} Check-in: ${checkin.value} Check-out: ${checkout.value} Nights: ${nights} Total: $${fmt(total)} Payment method: ${paymentMethod} Notes: ${notes || "none"}`; const mailtoLink = `mailto:${HOTEL_EMAIL}?subject=${encodeURIComponent("Room reservation — " + room.name)}&body=${encodeURIComponent(summary)}`; const whatsappLink = `https://wa.me/${HOTEL_WHATSAPP}?text=${encodeURIComponent(summary)}`; document.getElementById("emailUsBtn").href = mailtoLink; document.getElementById("whatsappUsBtn").href = whatsappLink; // send the full booking details to reservation@thehubaddis.com in the background const sendEmailBtn = document.getElementById("emailUsBtn"); const payload = { "First name": firstName, "Middle name": middleName, "Last name": lastName, "Customer email": email, "Customer phone": phone ? `${dial} ${phone}` : "not provided", "Room type": room.name, "Check-in": checkin.value, "Check-out": checkout.value, "Nights": nights, "Total": `$${fmt(total)}`, "Payment method": paymentMethod, "Notes": notes || "none" }; const emailSent = () => { confirmText.textContent = `Thanks, ${firstName}. Your ${room.name} is booked for ${nights} night(s), ${checkin.value} to ${checkout.value}, total $${fmt(total)}.${chargeNote} We'll confirm by email or WhatsApp shortly.`; if (sendEmailBtn) sendEmailBtn.textContent = "We got your booking — email the reservation team a copy"; }; const emailFailed = () => { if (sendEmailBtn) { sendEmailBtn.textContent = "Our email didn't reach the hotel — click here to send it"; sendEmailBtn.classList.add("alert"); } }; // 1) try Web3Forms first — proven to deliver to reservation@thehubaddis.com const web3Send = () => { if (!WEB3FORMS_ACCESS_KEY || WEB3FORMS_ACCESS_KEY === "PASTE_YOUR_WEB3FORMS_ACCESS_KEY_HERE") return Promise.resolve({ success: false }); return fetch("https://api.web3forms.com/submit", { method: "POST", headers: { "Content-Type": "application/json", Accept: "application/json" }, body: JSON.stringify({ access_key: WEB3FORMS_ACCESS_KEY, subject: `New room reservation — ${room.name}`, from_name: fullName, replyto: email, botcheck: "", ...payload }) }) .then(res => res.json().catch(() => ({ success: false }))) .catch(() => ({ success: false })); }; // 2) fall back to the server's own PHP mail endpoint const phpSend = () => { return fetch("send-booking.php", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(payload) }) .then(res => res.json().catch(() => ({ success: false }))) .catch(() => ({ success: false })); }; web3Send().then(w3 => { if (w3 && w3.success) return emailSent(); return phpSend().then(php => { if (php && php.success) emailSent(); else emailFailed(); }); }).catch(() => { // 3) last resort: the guest's own mail app sends it to reservation@thehubaddis.com emailFailed(); }); const chargeNote = ""; confirmText.textContent = `Thanks, ${firstName}. Your ${room.name} is booked for ${nights} night(s), ${checkin.value} to ${checkout.value}, total $${fmt(total)}.${chargeNote} We'll confirm by email or WhatsApp shortly.`; bookingForm.style.display = "none"; confirmView.classList.add("open"); // keep the guest's booking details on hand for the reservation voucher lastBooking = { guestName: fullName, roomName: room.name, checkin: checkin.value, checkout: checkout.value, nights, rate: room.price, total }; showVoucher(); }); // ---------- booking voucher (shown right after booking) ---------- let lastBooking = null; let currentVoucherUrl = null; const voucherWrap = document.getElementById("voucherWrap"); const voucherImg = document.getElementById("voucherImg"); function showVoucher(){ if (!lastBooking) return; voucherImg.src = ""; buildReservationCard(lastBooking).then(canvas => { currentVoucherUrl = canvas.toDataURL("image/jpeg", 0.92); voucherImg.src = currentVoucherUrl; voucherWrap.hidden = false; }).catch(err => { console.error("Voucher preview failed:", err); voucherWrap.hidden = false; voucherImg.style.display = "none"; }); } function formatDatePretty(iso){ if (!iso) return ""; const d = new Date(iso + "T00:00:00"); return d.toLocaleDateString("en-US", { weekday: "short", year: "numeric", month: "short", day: "numeric" }); } function loadImage(src){ return new Promise((resolve, reject) => { const img = new Image(); img.onload = () => resolve(img); img.onerror = reject; img.src = src; }); } function roundRect(ctx, x, y, w, h, r){ ctx.beginPath(); ctx.moveTo(x + r, y); ctx.arcTo(x + w, y, x + w, y + h, r); ctx.arcTo(x + w, y + h, x, y + h, r); ctx.arcTo(x, y + h, x, y, r); ctx.arcTo(x, y, x + w, y, r); ctx.closePath(); } async function buildReservationCard(b){ const W = 1000, H = 640; const canvas = document.createElement("canvas"); canvas.width = W; canvas.height = H; const ctx = canvas.getContext("2d"); const NAVY = "#182430", NAVY_LIGHT = "#2B3A48", AMBER = "#D9A441", TEAL = "#2F6E62", CREAM = "#F6F3EC", MUTED = "#9AA3AB"; try { await document.fonts.load("700 40px Fraunces"); await document.fonts.load("600 20px 'Work Sans'"); } catch (e) { /* fall back to default fonts if webfonts aren't ready */ } // background const grad = ctx.createLinearGradient(0, 0, W, H); grad.addColorStop(0, NAVY); grad.addColorStop(1, NAVY_LIGHT); ctx.fillStyle = grad; ctx.fillRect(0, 0, W, H); // amber border frame ctx.strokeStyle = AMBER; ctx.lineWidth = 3; roundRect(ctx, 20, 20, W - 40, H - 40, 18); ctx.stroke(); // logo (circular) — uses the embedded data-URI so the canvas never gets // tainted by an external/local file (that taint was silently blocking downloads) try { const logo = await loadImage(typeof LOGO_DATA_URI !== "undefined" ? LOGO_DATA_URI : "logo.jpg"); const r = 46, cx = W / 2, cy = 92; ctx.save(); ctx.beginPath(); ctx.arc(cx, cy, r, 0, Math.PI * 2); ctx.closePath(); ctx.clip(); ctx.drawImage(logo, cx - r, cy - r, r * 2, r * 2); ctx.restore(); ctx.strokeStyle = AMBER; ctx.lineWidth = 2.5; ctx.beginPath(); ctx.arc(cx, cy, r, 0, Math.PI * 2); ctx.stroke(); } catch (e) { /* logo image unavailable — continue without it */ } // hotel name + tagline ctx.textAlign = "center"; ctx.fillStyle = CREAM; ctx.font = "700 30px Fraunces, serif"; ctx.fillText("THE HUB HOTEL", W / 2, 175); ctx.fillStyle = AMBER; ctx.font = "700 13px 'Work Sans', sans-serif"; ctx.save(); ctx.letterSpacing = "3px"; ctx.fillText("RESERVATION CONFIRMATION", W / 2, 200); ctx.restore(); // divider ctx.strokeStyle = "rgba(217,164,65,0.5)"; ctx.lineWidth = 1; ctx.beginPath(); ctx.moveTo(90, 224); ctx.lineTo(W - 90, 224); ctx.stroke(); // guest name ctx.fillStyle = CREAM; ctx.font = "600 26px Fraunces, serif"; ctx.fillText(b.guestName, W / 2, 268); // white detail card const cardX = 70, cardY = 300, cardW = W - 140, cardH = 250; ctx.fillStyle = "#FFFFFF"; roundRect(ctx, cardX, cardY, cardW, cardH, 14); ctx.fill(); const rows = [ ["Room", b.roomName, "Nights", `${b.nights} night${b.nights > 1 ? "s" : ""}`], ["Check-in", formatDatePretty(b.checkin), "Check-out", formatDatePretty(b.checkout)] ]; let ry = cardY + 46; ctx.textAlign = "left"; rows.forEach(([l1, v1, l2, v2]) => { const colX1 = cardX + 34, colX2 = cardX + cardW / 2 + 10; ctx.fillStyle = MUTED; ctx.font = "600 12px 'Work Sans', sans-serif"; ctx.fillText(l1.toUpperCase(), colX1, ry); ctx.fillText(l2.toUpperCase(), colX2, ry); ctx.fillStyle = NAVY; ctx.font = "600 19px 'Work Sans', sans-serif"; ctx.fillText(v1, colX1, ry + 26); ctx.fillText(v2, colX2, ry + 26); ry += 84; }); ctx.fillStyle = MUTED; ctx.font = "600 12px 'Work Sans', sans-serif"; ctx.fillText("RATE", cardX + 34, ry); ctx.fillStyle = NAVY; ctx.font = "600 19px 'Work Sans', sans-serif"; ctx.fillText(`$${fmt(b.rate)} / night`, cardX + 34, ry + 26); // dashed separator + total ctx.strokeStyle = "#D8DDD9"; ctx.setLineDash([5, 5]); ctx.beginPath(); ctx.moveTo(cardX + 34, cardY + cardH - 56); ctx.lineTo(cardX + cardW - 34, cardY + cardH - 56); ctx.stroke(); ctx.setLineDash([]); ctx.fillStyle = MUTED; ctx.font = "600 12px 'Work Sans', sans-serif"; ctx.fillText("TOTAL", cardX + 34, cardY + cardH - 24); ctx.textAlign = "right"; ctx.fillStyle = TEAL; ctx.font = "700 26px Fraunces, serif"; ctx.fillText(`$${fmt(b.total)}`, cardX + cardW - 34, cardY + cardH - 18); // footer note ctx.textAlign = "center"; ctx.fillStyle = "#B9C0C6"; ctx.font = "500 13px 'Work Sans', sans-serif"; ctx.fillText("Please show this card at check-in · reservation@thehubaddis.com", W / 2, H - 46); ctx.fillStyle = "#8A929A"; ctx.font = "400 11px 'Work Sans', sans-serif"; ctx.fillText(`Issued ${new Date().toLocaleDateString("en-US", { year: "numeric", month: "short", day: "numeric" })}`, W / 2, H - 26); return canvas; } const saveCardBtn = document.getElementById("saveCardBtn"); function downloadBlob(blob, filename){ const url = URL.createObjectURL(blob); const a = document.createElement("a"); a.href = url; a.download = filename; document.body.appendChild(a); a.click(); a.remove(); URL.revokeObjectURL(url); } saveCardBtn.addEventListener("click", async () => { if (!lastBooking) return; saveCardBtn.disabled = true; try { const canvas = await buildReservationCard(lastBooking); const blob = await new Promise((resolve, reject) => { canvas.toBlob(b => b ? resolve(b) : reject(new Error("toBlob returned null")), "image/jpeg", 0.95); }); const fileSafeRoom = lastBooking.roomName.replace(/[^a-z0-9]+/gi, "-"); downloadBlob(blob, `TheHubHotel-Reservation-${fileSafeRoom}-${lastBooking.checkin}.jpg`); } catch (err) { console.error("Reservation card download failed:", err); alert("Sorry, the download didn't work. Please try again, or use WhatsApp/Email below instead."); } finally { saveCardBtn.disabled = false; } }); // hide the old voucher whenever the modal is opened fresh function resetVoucher(){ voucherWrap.hidden = true; voucherImg.style.display = ""; voucherImg.src = ""; currentVoucherUrl = null; }