// Detect language const getLang = () => { const html = document.querySelector("html"); const lang = html?.getAttribute("lang") || "ar"; return lang.toLowerCase().includes("en") ? "en" : "ar"; }; const LANG = getLang(); const dict = { "من نحن": { ar: "من نحن", en: "About Us" }, "الدعم والمساعدة": { ar: "الدعم والمساعدة", en: "Support & Help" }, "السياسات و الخدمات": { ar: "السياسات و الخدمات", en: "Policies & Services" }, "الشحن والضمان": { ar: "الشحن والضمان", en: "Shipping & Warranty" }, "التبديل والإسترجاع": { ar: "التبديل والإسترجاع", en: "Exchange & Return" }, "مصنوع يدوياً بالحب": { ar: "مصنوع يدوياً بالحب", en: "Handmade with Love" } }; const t = (key) => dict[key]?.[LANG] || key; const createAccordion = (data, parent, order = 'before') => { if (!data || !Array.isArray(data) || data.length === 0 || !parent) return; const section = document.createElement('section'); section.className = 'accordion-section'; const accorCon = document.createElement('div'); accorCon.className = 'accordion'; data.forEach(({ title, content }) => { const button = document.createElement('button'); button.className = 'accordion-button'; button.innerHTML = `${title} `; const contentDiv = document.createElement('div'); contentDiv.className = 'accordion-content'; contentDiv.innerHTML = typeof content === 'string' && content.includes('<') ? content : `

${content}

`; contentDiv.style.maxHeight = null; // reset accorCon.append(button, contentDiv); }); section.append(accorCon); order === 'before' ? parent.before(section) : parent.after(section); }; const initAccordion = (parentSelector = '.accordion') => { const accordions = document.querySelectorAll(parentSelector); if (!accordions.length) return; accordions.forEach((accorCon) => { const buttons = accorCon.querySelectorAll('.accordion-button'); buttons.forEach((button) => { const contentDiv = button.nextElementSibling; if (!contentDiv || !contentDiv.classList.contains('accordion-content')) return; contentDiv.style.maxHeight = null; button.addEventListener('click', () => { const isActive = button.classList.toggle('active'); buttons.forEach((btn) => { const cont = btn.nextElementSibling; if (btn !== button) { btn.classList.remove('active'); cont.style.maxHeight = null; } }); contentDiv.style.maxHeight = isActive ? `${contentDiv.scrollHeight}px` : null; }); }); }); }; const validData = [ { title: t('الشحن والضمان'), content: LANG === "ar" ? `

للاطلاع على سياسة الشحن والضمان اضغط هنا

` : `

To view the shipping & warranty policy Click here

` }, { title: t('التبديل والإسترجاع'), content: LANG === "ar" ? `

للإطلاع على سياسة الإستبدال او الإسترجاع اضغط هنا

` : `

To view the exchange or return policy Click here

` }, { title: t('مصنوع يدوياً بالحب'), content: LANG === "ar" ? `

صُنع يدويًا بالحب:
كل عطر من ماتش يُصنع بعناية فائقة…

` : `

Handmade with love:
Every Match perfume is carefully crafted…

` } ]; const footerAccordionData = () => { const links = document.querySelector('.footer-list'); if (!links) return []; const items = [...links.children]; const aboutItem = items[0] ? [items[0]] : []; const supportItems = items.slice(1, 3); const linkItems = items.slice(3); const createListHTML = (arr) => { const ul = document.createElement('ul'); arr.forEach((el) => ul.appendChild(el.cloneNode(true))); return ul.outerHTML; }; return [ { title: t('من نحن'), content: createListHTML(aboutItem) }, { title: t('الدعم والمساعدة'), content: createListHTML(supportItems) }, { title: t('السياسات و الخدمات'), content: createListHTML(linkItems) }, ]; }; document.addEventListener('DOMContentLoaded', () => { const footer = document.querySelector('.store-footer__inner .grid div:nth-of-type(2)'); if (footer) { createAccordion(footerAccordionData(), footer, 'after'); } const proForm = document.querySelector('.product-single salla-payments'); if (proForm) { createAccordion(validData, proForm, 'after'); } initAccordion('.accordion'); });