import * as React from 'react'
import { ListItem } from '@planview/pv-uikit'
import type { ListItemProps } from '@planview/pv-uikit'
import type { ToolbarButtonProps } from '../button'

/**
 * @method transformButtonToListItem
 * Transform a button element to a ListItem
 * for use in more menu
 */
export const transformButtonToListItem = (
    child: React.ReactElement<
        { onClick?: unknown } & Omit<ToolbarButtonProps, 'onClick'>
    >,
    key: number | string
): React.ReactElement<ListItemProps> => (
    <ListItem
        key={key}
        label={(child.props.children || child.props.tooltip || '') as string}
        icon={child.props.icon}
        selected={child.props.activated}
        onActivate={child.props.onClick as any}
    />
)
