'use client';

import { MediaPlayButton } from 'media-chrome/react';
import { cn } from '@djangocfg/ui-core/lib';
import {
  Tooltip,
  TooltipContent,
  TooltipTrigger,
} from '@djangocfg/ui-core/components';
import type { ComponentProps, ReactNode } from 'react';

export type PlayButtonProps = ComponentProps<typeof MediaPlayButton> & {
  /** Tooltip copy. Defaults to `"Play / Pause"`. Pass `false` to opt out. */
  readonly label?: ReactNode | false;
};

export function PlayButton({ className, label, ...props }: PlayButtonProps) {
  const button = (
    <MediaPlayButton
      {...props}
      className={cn(
        'media-control-square video-player__control h-8 w-8',
        className,
      )}
    />
  );

  if (label === false) return button;

  return (
    <Tooltip>
      <TooltipTrigger asChild>{button}</TooltipTrigger>
      <TooltipContent side="top">{label ?? 'Play / Pause'}</TooltipContent>
    </Tooltip>
  );
}
