'use client';

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

export function Pip({ className, label, ...props }: PipProps) {
  const button = (
    <MediaPipButton
      {...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 ?? 'Picture in picture'}</TooltipContent>
    </Tooltip>
  );
}
