import onFind from './dom/onFind'
import { setupMenuForAria, toggleMenu } from './dom/popupMenu'

onFind('.TranslationsTab-actionsToggle', (button: HTMLElement) => {
  const actionWrapper = button.closest('.TranslationsTab-actionsWrapper')

  if (actionWrapper) {
    const actions = actionWrapper.querySelector<HTMLElement>(
      '.TranslationsTab-actions',
    )

    if (actions) {
      setupMenuForAria(actions, button)

      button.addEventListener('click', (e) => {
        toggleMenu(actions, button)
      })
    }
  }
})
