export { dsTextButtonToggle, dsTextButtonToggleAll };

function dsTextButtonToggle(toggleElements = []) {
  if (!toggleElements.length) return;
  toggleElements.forEach((toggleEl) => {
    toggleEl.addEventListener('click', () => {
      if (toggleEl.classList.contains('ds-text-btn-toggle--disabled')) return;
      toggleEl.classList.toggle('ds-text-btn-toggle--selected');
      const ariaChecked = toggleEl.getAttribute('aria-checked') === 'true' ? 'false' : 'true';
      toggleEl.setAttribute('aria-checked', ariaChecked);
    });
  });
}

function dsTextButtonToggleAll() {
  const toggleElements = Array.from(document.getElementsByClassName('ds-text-btn-toggle'));
  dsTextButtonToggle(toggleElements);
}
