var express = require("express"); var router = express.Router(); const moment = require("moment-timezone"); // Helper: Group timezones by region for the timezone selection screen function getTimezoneGroups() { const regions = { "USA/CANADA": [ "America/Los_Angeles", "America/Denver", "America/New_York", "America/Halifax", ], EUROPE: [ "Europe/Berlin", "Europe/Helsinki", "Europe/Dublin", "Europe/Samara", ], ASIA: ["Asia/Hong_Kong", "Asia/Jakarta", "Asia/Kabul", "Asia/Kathmandu"], "SOUTH AMERICA": [ "America/Bogota", "America/Campo_Grande", "America/Caracas", "America/Lima", ], }; const groups = {}; for (const region in regions) { groups[region] = regions[region].map((tz) => ({ value: tz, label: moment().tz(tz).zoneAbbr() + " " + moment().tz(tz).format("h:mma"), })); } return groups; } // Helper: All timezones for dropdown function getAllTimezones() { return moment.tz.names().map((tz) => ({ value: tz, label: tz, })); } // Helper: Generate week days and slots function getWeekDaysAndSlots(selectedTz) { const weekDays = []; const today = moment().tz(selectedTz); for (let i = 0; i < 7; i++) { const day = today.clone().add(i, "days"); weekDays.push({ label: day.format("dddd"), date: day.format("MMMM D"), dateISO: day.format("YYYY-MM-DD"), slots: [ "9:00am", "9:15am", "9:30am", "9:45am", "10:00am", "10:15am", "10:30am", "10:45am", "11:00am", "11:15am", "11:30am", "11:45am", "12:00pm", "12:15pm", "12:30pm", "12:45pm", "1:00pm", "1:15pm", ], }); } return { weekDays, maxSlots: 17 }; } // Timezone selection screen router.get("/timezone", function (req, res) { res.render("timezone", { timezones: getAllTimezones(), timezoneGroups: getTimezoneGroups(), }); }); // Calendar slot selection screen router.get("/calendar", function (req, res) { const selectedTimezone = req.query.tz || "America/New_York"; const { weekDays, maxSlots } = getWeekDaysAndSlots(selectedTimezone); res.render("calendar", { selectedTimezone, weekDays, maxSlots, showPrevWeek: false, // For demo, only next week link }); }); // Booking form screen router.get("/book", function (req, res) { const selectedTimezone = req.query.tz || "America/New_York"; res.render("booking-form", { selectedTimezone, }); }); // Booking POST (simulate success) router.post("/book", function (req, res) { // Here you would save booking info to DB res.redirect("/success"); }); // Success screen router.get("/success", function (req, res) { res.render("success"); }); // Home page redirect to timezone selection router.get("/", function (req, res) { res.redirect("/timezone"); }); module.exports = router;