import { Editor, useEditor } from '@bigbluebutton/editor'
import * as React from 'react'
import { TLUiMenuChild } from '../hooks/menuHelpers'
import { useBreakpoint } from '../hooks/useBreakpoint'
import { useMenuSchema } from '../hooks/useMenuSchema'
import { useReadonly } from '../hooks/useReadonly'
import { useTranslation } from '../hooks/useTranslation/useTranslation'
import { LanguageMenu } from './LanguageMenu'
import { Button } from './primitives/Button'
import * as M from './primitives/DropdownMenu'
import { Kbd } from './primitives/Kbd'
export const Menu = React.memo(function Menu() {
const msg = useTranslation()
return (
)
})
function MenuContent() {
const editor = useEditor()
const msg = useTranslation()
const menuSchema = useMenuSchema()
const breakpoint = useBreakpoint()
const isReadonly = useReadonly()
function getMenuItem(
editor: Editor,
item: TLUiMenuChild,
parent: TLUiMenuChild | null,
depth: number
) {
if (!item) return null
switch (item.type) {
case 'custom': {
if (isReadonly && !item.readonlyOk) return null
if (item.id === 'LANGUAGE_MENU') {
return
}
return null
}
case 'group': {
if (isReadonly && !item.readonlyOk) return null
return (
2)
? 'tiny'
: 'medium'
}
key={item.id}
>
{item.children.map((child) => getMenuItem(editor, child, item, depth + 1))}
)
}
case 'submenu': {
if (isReadonly && !item.readonlyOk) return null
return (
{item.children.map((child) => getMenuItem(editor, child, item, depth + 1))}
)
}
case 'item': {
if (isReadonly && !item.readonlyOk) return null
const { id, checkbox, menuLabel, label, onSelect, kbd } = item.actionItem
const labelToUse = menuLabel ?? label
const labelStr = labelToUse ? msg(labelToUse) : undefined
if (checkbox) {
// Item is in a checkbox group
return (
onSelect('menu')}
title={labelStr ? labelStr : ''}
checked={item.checked}
disabled={item.disabled}
>
{labelStr && {labelStr}}
{kbd && {kbd}}
)
}
// Item is a button
return (
onSelect('menu')}
disabled={item.disabled}
/>
)
}
}
}
return <>{menuSchema.map((item) => getMenuItem(editor, item, null, 0))}>
}