TheTiffinFood/pricing.js

74 lines
2.7 KiB
JavaScript

const pricing = {
balanced: {
name: "Balanced",
description: "A little bit of everything, dialed into a rhythm you can actually keep.",
prices: [5000, 4000, 2000],
},
bulk: {
name: "Bulk",
description: "Intentional calories, complex carbs and protein in a bigger, bolder box.",
prices: [6000, 5000, 2500],
},
protein: {
name: "Protein",
description: "Pure protein power for the work you put in, from first rep to last.",
prices: [6500, 5500, 3000],
},
lean: {
name: "Lean",
description: "Minimal fats. Maximum clarity. Light, clean meals to help you move sharper.",
prices: [7000, 6000, 3500],
},
};
const WHATSAPP_NUMBER = "919453226814";
const options = [
{ label: "Breakfast, lunch & dinner", detail: "3 meals a day" },
{ label: "Lunch & dinner", detail: "2 meals a day" },
{ label: "Dinner", detail: "1 meal a day" },
];
const mode = new URLSearchParams(window.location.search).get("mode") || "balanced";
const selected = pricing[mode] || pricing.balanced;
document.title = `${selected.name} mode pricing — The Tiffin Food`;
document.querySelector("#mode-title").textContent = `${selected.name} mode`;
document.querySelector("#mode-description").textContent = selected.description;
document.querySelector("#pricing-options").innerHTML = options
.map((option, index) => `
<article class="price-card">
<div>
<p class="price-index">0${index + 1}</p>
<h3>${option.label}</h3>
<p>${option.detail}</p>
</div>
<strong>₹${selected.prices[index].toLocaleString("en-IN")}<span>/ month</span></strong>
<a class="button button-primary choose-box" href="#box" data-box="${option.label} — ₹${selected.prices[index].toLocaleString("en-IN")} / month">Choose this box <span>↗</span></a>
</article>
`)
.join("");
document.querySelectorAll(".choose-box").forEach((button) => {
button.addEventListener("click", () => {
const box = document.querySelector("#box");
box.value = button.dataset.box;
box.focus();
});
});
document.querySelector("#customize-form").addEventListener("submit", (event) => {
event.preventDefault();
const form = new FormData(event.currentTarget);
const message = [
"Hi The Tiffin Food! I would like to customize my tiffin.",
"",
`Plan: ${selected.name} mode`,
`Your box: ${form.get("box")}`,
`Destination: ${form.get("destination")}`,
`Preferred delivery window: ${form.get("timing")}`,
`Meal preferences: ${form.get("preferences") || "None specified"}`,
].join("\n");
document.querySelector(".form-note").textContent = "Opening WhatsApp with your tiffin preferences.";
window.location.href = `https://wa.me/${WHATSAPP_NUMBER}?text=${encodeURIComponent(message)}`;
});