'use client';

import { MediaFullscreenButton } 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 FullscreenProps = ComponentProps<typeof MediaFullscreenButton> & {
  /** Tooltip copy. Defaults to `"Fullscreen"`. Pass `false` to opt out. */
  readonly label?: ReactNode | false;
};

export function Fullscreen({ className, label, ...props }: FullscreenProps) {
  const button = (
    <MediaFullscreenButton
      {...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 ?? 'Fullscreen'}</TooltipContent>
    </Tooltip>
  );
}
