import type { DisplayConfig, Label, MenuHost, MenuModel, SelectorItem } from './m3u8-types' import { releaseAll } from './cleanup' export default function createMenu(art: MenuHost, name: string, icon: string) { const owned = { control: false, setting: false } let model: MenuModel | null = null function remove(surface: 'control' | 'setting'): void { if (!owned[surface]) return owned[surface] = false if (surface === 'control') { if (art.controls.cache.has(name)) art.controls.remove(name) } else if (art.setting.find(name)) { art.setting.remove(name) } } function clear(): void { model = null releaseAll([() => remove('control'), () => remove('setting')]) } function update(next: MenuModel | null, config: DisplayConfig, active: () => boolean, select: (item: SelectorItem, title: string) => Promise