const detailsElements = document.getElementsByTagName('details');
const dropdown = Array.from(detailsElements);

const save = () => {
    dropdown.forEach((details, i) => {
        localStorage.setItem(`details${i}`, details.hasAttribute('open'));
    });
};

dropdown.forEach((details, i) => {
    const isOpen = JSON.parse(localStorage.getItem(`details${i}`)) || false;
    details.toggleAttribute('open', isOpen);
    details.addEventListener('toggle', save);

    const svg = details.querySelector('summary svg');
    if (svg) {
        svg.style.transition = isOpen ? 'none' : '';
    }
});

setTimeout(() => {
    dropdown.forEach(details => {
        const svg = details.querySelector('summary svg');
        if (svg) svg.style.transition = '';
    });
}, 100);