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 setChecked = (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?.lastElementChild const $end = it.$controllerBottom.lastElementChild! 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') { setChecked(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) }) function _register(menu: MenuBar) { const repeated = menus.find((m) => m.name == menu.name) if (repeated) unregister(repeated.name) const { name, icon, children, position } = menu const isTop = position == 'top' && $targets.length == 2 let $menu: string = '' const $button = ` ` if (menu.children) { $menu = `