function selectButtonCombobox(button) {
    const group = button.getAttribute('data-group');
    const value = button.getAttribute('data-value');

    document.querySelectorAll(`[data-group="${group}"]`).forEach(btn => {
        btn.classList.remove('active');
    });

    button.classList.add('active');

    const hiddenInput = document.getElementById(group);
    if (hiddenInput) {
        hiddenInput.value = value;
    }

    const hideInput = button.getAttribute('data-on-select-hide-element');

    if (hideInput) {
        hideInput.split(',').forEach(id => {
            const container = document.getElementById(id.trim());
            if (container) container.style.display = 'none';
        });
    }
    const showInput = button.getAttribute('data-on-select-show-element');
    if (showInput) {
        const input = document.getElementById(showInput);
        if (input) input.style.display = 'block';
    }
}

function selectButtonComboboxByGroupAndValue(dataGroup, value) {
    const hiddenInput = document.getElementById(dataGroup);
    if (hiddenInput) {
        hiddenInput.value = value;
    }

    const button = document.querySelector(`.combobox-btn[data-group="${dataGroup}"][data-value="${value}"]`);

    if (button) {
        selectButtonCombobox(button);
    }
}
document.addEventListener('DOMContentLoaded', () => {
    document.addEventListener('click', e => {
        const btn = e.target.closest('.combobox-btn');
        if (btn) {
            selectButtonCombobox(btn);
        }
    });
});

document.addEventListener('DOMContentLoaded', () => {
    document.querySelectorAll('input[type="hidden"]').forEach(hidden => {
        const groupId = hidden.id;
        const value = hidden.value;
        const groupElements = document.querySelectorAll(`[data-group="${groupId}"]`);
        groupElements.forEach(el => {
            if (el.getAttribute('data-value') === value) {
                el.classList.add('silent-change');
                el.click();
                el.classList.remove('silent-change');
            }
        });
    });
});
