import { dropdown, dropdownHoverable, dropItem, expand, expandBottom, textIcon } from '../components/ControllerBottom.style' import { icon as iconCls, tooltip } from '../style' import type { MenuBar, UIInterface } from '../types' import { siblings } from '../utils' const _select = (elm: HTMLElement) => { const selected = elm.getAttribute('aria-checked') == 'true' elm.setAttribute('aria-checked', `${!selected}`) siblings(elm, (it) => it.setAttribute('aria-checked', `${selected}`)) } export default (it: UIInterface) => { const initialState = it.config.menu const menus: MenuBar[] = [] const $top = it.$controllerBar?.children[1] const $end = it.$controllerBottom.children[1]! const $targets = [$top, $end].filter(Boolean) as HTMLDivElement[] function clickHandler(e: Event) { const elm: HTMLElement = e.target as HTMLElement const label = elm.getAttribute('aria-label') const target = menus.find((it) => it.name == label) if (!target || elm.getAttribute('aria-checked') == 'true') return if (elm.tagName.toUpperCase() == 'SPAN') { _select(elm) target.onChange?.( target.children![+elm.getAttribute('data-index')!]!, elm.parentElement!.previousElementSibling as HTMLButtonElement, it.player ) } else if (elm.tagName.toUpperCase() == 'BUTTON') { target.onClick?.(elm as any, it.player) } } $targets.forEach((it) => { it.addEventListener('click', clickHandler) }) it.menu.register = function register(menu: MenuBar) { const { name, icon, children, position } = menu const isTop = position == 'top' && $targets.length == 2 let $menu: string = '' const $button = ` ` if (menu.children) { $menu = `