<script>
(() => {
const run = () => {
const routes = {
'/o-kompanii': 'about',
'/usloviya-oplaty': 'payment',
'/usloviya-dostavki': 'delivery',
'/kontakty': 'contacts'
};
const type = routes[location.pathname.replace(/\/$/, '')];
if (!type || document.body.dataset.agInfoReady === '1') return;
document.body.dataset.agInfoReady = '1';
document.body.classList.add('ag-info-page', `ag-info-${type}`);
const grids = [...document.querySelectorAll('main .uk-section > .uk-container > .uk-grid')];
if (type === 'about') {
const host = grids[0]?.querySelector('.uk-width-1-1');
if (host && !host.querySelector('.ag-about-benefits')) {
const benefits = document.createElement('section');
benefits.className = 'ag-about-benefits';
benefits.setAttribute('aria-label', 'Преимущества компании');
benefits.innerHTML = [
['7+ лет на рынке', 'Надёжный партнёр с 2017 года'],
['Широкий ассортимент', 'Более 2 000 товаров'],
['Доставка по России', 'Быстро и надёжно'],
['Консультации экспертов', 'Поможем с выбором']
].map(([title, text]) => `<div class="ag-about-benefit"><strong>${title}</strong><span>${text}</span></div>`).join('');
host.append(benefits);
}
}
if (type === 'payment' || type === 'delivery') {
const contentGrid = grids[2];
if (!contentGrid) return;
contentGrid.firstElementChild?.classList.add('ag-info-meta');
const source = contentGrid.lastElementChild;
if (!source || source.querySelector('.ag-info-card-grid')) return;
source.classList.add('ag-info-content-grid');
const nodes = [...source.children];
const headings = nodes.filter(node => node.tagName === 'H2');
const cardGrid = document.createElement('div');
cardGrid.className = 'ag-info-card-grid';
if (type === 'payment') {
headings.forEach((heading, index) => {
const card = document.createElement('section');
card.className = 'ag-info-card';
card.append(heading);
let next = heading.nextElementSibling;
while (next && next.tagName !== 'H2') {
const current = next;
next = next.nextElementSibling;
card.append(current);
}
cardGrid.append(card);
});
source.prepend(cardGrid);
const faq = document.createElement('section');
faq.className = 'ag-info-faq';
faq.innerHTML = '<h2>Частые вопросы по оплате</h2>' +
'<details><summary>Как получить счёт на оплату?</summary><p>Менеджер АгроСоюза подготовит и выставит счёт от ООО «АгроТрейдСнаб».</p></details>' +
'<details><summary>Можно ли оплатить при получении?</summary><p>Оплата наличными возможна при самовывозе.</p></details>' +
'<details><summary>Как уточнить доступный способ оплаты?</summary><p>Подробности сообщит менеджер при согласовании заказа.</p></details>';
source.append(faq);
}
if (type === 'delivery') {
const firstHeading = headings[0];
const secondHeading = headings[1];
if (firstHeading && secondHeading) {
const transport = document.createElement('section');
transport.className = 'ag-info-card';
const region = document.createElement('section');
region.className = 'ag-info-card';
const pickup = document.createElement('section');
pickup.className = 'ag-info-card';
transport.append(firstHeading);
let node = firstHeading.nextElementSibling;
while (node && node !== secondHeading) {
const current = node;
node = node.nextElementSibling;
if (current.matches('.uk-panel.uk-width-2-3\\@m')) region.append(current);
else transport.append(current);
}
const regionHeading = document.createElement('h2');
regionHeading.textContent = 'Доставка по регионам';
region.prepend(regionHeading);
pickup.append(secondHeading);
while (node) {
const current = node;
node = node.nextElementSibling;
pickup.append(current);
}
cardGrid.append(transport, pickup, region);
source.prepend(cardGrid);
}
const steps = document.createElement('section');
steps.className = 'ag-delivery-steps';
steps.innerHTML = '<h2>Как проходит доставка</h2><div class="ag-delivery-steps__grid">' +
[
['1', 'Согласование', 'Уточняем заказ и адрес получения'],
['2', 'Выбор доставки', 'Подбираем удобную транспортную компанию'],
['3', 'Отправка', 'Передаём заказ перевозчику'],
['4', 'Получение', 'Вы получаете заказ в своём городе']
].map(([n, title, text]) => `<div class="ag-delivery-step"><b>${n}</b><strong>${title}</strong><span>${text}</span></div>`).join('') +
'</div>';
source.append(steps);
}
}
if (type === 'contacts') {
const contactGrid = grids[1];
const requisitesGrid = grids[2];
contactGrid?.classList.add('ag-contacts-grid');
requisitesGrid?.classList.add('ag-requisites-grid');
}
};
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', run, { once: true });
} else {
run();
}
})();
</script>