function formatRub(value) { return new Intl.NumberFormat("ru-RU").format(Math.round(value)); } function formatRubShort(value) { const abs = Math.abs(value); if (abs >= 1000000) { return `${(value / 1000000).toFixed(1)} млн ₽`; } return `${formatRub(value)} ₽`; } function buildFooterSocialLinksMarkup() { return `
`; } function normalizeFooterContacts() { const footer = document.querySelector("footer"); footer?.querySelectorAll(".grid > div:last-child li").forEach((item) => { item.textContent = item.textContent.replace(/^[^+\p{L}\p{N}]+/u, "").trim(); }); } function initFooterSocialLinks() { const footer = document.querySelector("footer"); const footerColumns = footer?.querySelectorAll(".grid > div"); const contactColumn = footerColumns?.[footerColumns.length - 1]; if (!contactColumn || contactColumn.querySelector("[data-footer-socials]")) return; contactColumn.insertAdjacentHTML("beforeend", buildFooterSocialLinksMarkup()); } function initMobileMenu() { const mobileMenuButton = document.getElementById("mobile-menu-btn"); const mobileMenu = document.getElementById("mobile-menu"); if (!mobileMenuButton || !mobileMenu) return; mobileMenuButton.addEventListener("click", () => { mobileMenu.classList.toggle("hidden"); }); mobileMenu.querySelectorAll("a, button").forEach((item) => { item.addEventListener("click", () => mobileMenu.classList.add("hidden")); }); } function initSeedCalculator() { const form = document.getElementById("seed-calc-form"); if (!form) return; form.addEventListener("submit", (event) => { event.preventDefault(); const density = parseFloat(document.getElementById("calc-density").value); const weight = parseFloat(document.getElementById("calc-weight").value); const germination = parseFloat(document.getElementById("calc-germination").value); if (!(density > 0 && weight > 0 && germination > 0)) return; const result = (density * weight) / (germination / 100); document.getElementById("result-value").textContent = result.toFixed(1); document.getElementById("calc-result")?.classList.remove("hidden"); }); } function initProfitCalculator() { const form = document.getElementById("profit-calc-form"); if (!form) return; form.addEventListener("submit", (event) => { event.preventDefault(); const area = parseFloat(document.getElementById("profit-area")?.value || "0"); const yieldPerHa = parseFloat(document.getElementById("profit-yield")?.value || "0"); const pricePerTon = parseFloat(document.getElementById("profit-price")?.value || "0"); const costPerHa = parseFloat(document.getElementById("profit-cost")?.value || "0"); const subsidyPct = parseFloat(document.getElementById("profit-subsidy")?.value || "0"); if (!(area > 0 && yieldPerHa > 0 && pricePerTon > 0 && costPerHa >= 0 && subsidyPct >= 0)) return; const grossRevenue = area * yieldPerHa * pricePerTon; const grossCost = area * costPerHa; const subsidy = grossCost * (subsidyPct / 100); const netCost = grossCost - subsidy; const profit = grossRevenue - netCost; const roi = netCost > 0 ? (profit / netCost) * 100 : 0; document.getElementById("profit-revenue").textContent = formatRubShort(grossRevenue); document.getElementById("profit-net").textContent = formatRubShort(profit); document.getElementById("profit-roi").textContent = `${Math.round(roi)}%`; document.getElementById("profit-result")?.classList.remove("hidden"); }); } document.addEventListener("DOMContentLoaded", () => { initMobileMenu(); normalizeFooterContacts(); initFooterSocialLinks(); initSeedCalculator(); initProfitCalculator(); });