import { type ComponentPropsWithoutRef, type ReactNode } from 'react';
import { DropdownMenu as RMenu } from 'radix-ui';

export const Menu = RMenu.Root;
export const MenuTrigger = RMenu.Trigger;

export const MenuContent = ({
  children,
  ...props
}: ComponentPropsWithoutRef<typeof RMenu.Content>) => (
  <RMenu.Portal>
    <RMenu.Content className="mta-menu" sideOffset={6} {...props}>
      {children}
    </RMenu.Content>
  </RMenu.Portal>
);

export const MenuItem = ({
  icon,
  shortcut,
  children,
  ...props
}: ComponentPropsWithoutRef<typeof RMenu.Item> & {
  icon?: ReactNode;
  shortcut?: string;
}) => (
  <RMenu.Item className="mta-menu-item" {...props}>
    {icon && <span className="ph">{icon}</span>}
    {children}
    {shortcut && <span className="sc">{shortcut}</span>}
  </RMenu.Item>
);

export const MenuSeparator = () => (
  <RMenu.Separator className="mta-menu-sep" />
);

export const MenuSurface = ({ children }: { children: ReactNode }) => (
  <div className="mta-menu">{children}</div>
);

export const MenuRow = ({
  icon,
  shortcut,
  children,
}: {
  icon?: ReactNode;
  shortcut?: string;
  children: ReactNode;
}) => (
  <div className="mta-menu-item">
    {icon && <span className="ph">{icon}</span>}
    {children}
    {shortcut && <span className="sc">{shortcut}</span>}
  </div>
);
