(function () { const PRODUCT_ID = 1599; // CENY NÜRBURGRING const PRICE_MAP = { 2:900, 3:1350, 4:1750, 5:2150, 6:2400, 7:2700, 8:3000 }; // DODATKI (ID checkboxa -> label + cena) const ADDON_MAP = { "102": { label: "Podpięcie przyczepy", price: 100 }, "111": { label: "Wózki transportowe pod koła", price: 100 } }; const SELECTORS = { pickupDate: "#pickup-date", dropoffDate: "#dropoff-date", summaryBox: ".booking-pricing-info", cartForm: "form.cart" }; const onNurbPage = () => document.body.classList.contains("postid-" + PRODUCT_ID); function parsePLDate(val) { if (!val) return null; val = String(val).trim(); let m = val.match(/^(\d{2})\/(\d{2})\/(\d{4})$/); if (m) return new Date(+m[3], +m[2]-1, +m[1]); m = val.match(/^(\d{2})\.(\d{2})\.(\d{4})$/); if (m) return new Date(+m[3], +m[2]-1, +m[1]); return null; } // INKLUZYWNE LICZENIE DNI (jak MAXI) function diffDaysInclusive(d1, d2) { const ms = 24 * 60 * 60 * 1000; const a = new Date(d1.getFullYear(), d1.getMonth(), d1.getDate()); const b = new Date(d2.getFullYear(), d2.getMonth(), d2.getDate()); const diff = Math.round((b - a) / ms); return diff >= 0 ? diff + 1 : null; } function formatPLN(x) { return new Intl.NumberFormat("pl-PL", { style: "currency", currency: "PLN" }) .format(Number(x || 0)); } function ensureHidden(name, value) { const form = document.querySelector(SELECTORS.cartForm); if (!form) return; let el = form.querySelector(`input[name="${name}"]`); if (!el) { el = document.createElement("input"); el.type = "hidden"; el.name = name; form.appendChild(el); } el.value = value ?? ""; } // AUTO: jeśli w labelu jest "za dobę" -> per_day, inaczej one_time function detectTypeFromLabel(labelEl) { const txt = (labelEl?.textContent || "").toLowerCase(); return txt.includes("za dob") ? "per_day" : "one_time"; } function getAddons(days) { let addonsTotal = 0; const addonsList = []; // TAK SAMO JAK W MAXI document.querySelectorAll("label.custom-block.checked").forEach(label => { const inp = label.querySelector('input.booking-extra[name="extras[]"][type="checkbox"]'); if (!inp) return; const key = String(inp.value || "").trim(); if (!ADDON_MAP[key]) return; const type = detectTypeFromLabel(label); const unit = Number(ADDON_MAP[key].price || 0); const cost = (type === "per_day") ? unit * days : unit; addonsTotal += cost; addonsList.push({ key, label: ADDON_MAP[key].label, type, unit, cost }); }); // unikat const uniq = []; const seen = new Set(); addonsList.forEach(a => { if (!seen.has(a.key)) { seen.add(a.key); uniq.push(a); } }); return { addonsTotal, addonsList: uniq }; } function renderOurBreakdown(days, base, addonsTotal, total, addonsList) { const box = document.querySelector(SELECTORS.summaryBox); if (!box) return; let block = box.querySelector(".nurb-breakdown"); if (!block) { block = document.createElement("div"); block.className = "nurb-breakdown"; block.style.marginTop = "10px"; block.style.fontSize = "13px"; block.style.opacity = "0.92"; box.appendChild(block); } const addonsTxt = addonsList.length ? addonsList.map(a => { const suffix = (a.type === "per_day") ? ` (${formatPLN(a.unit)}/doba × ${days})` : ""; return `${a.label}: ${formatPLN(a.cost)}${suffix}`; }).join(" • ") : "brak"; block.innerHTML = `