// src/components/ui/rich-menu.tsx — rich dropdown-menu building blocks
// (icon-tile + bold title + description), généralisés depuis le pattern
// `ImportMenuItem` de keywords-toolbar.tsx. Bâtis sur le DropdownMenu radix
// (dropdown-menu.tsx). Palette = tokens shadcn, la couleur de tuile est passée
// par l'appelant via `iconClassName` (ex. "bg-blue-600/90 text-white").
"use client";

import type * as React from "react";
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
import { cn } from "@/lib/utils";

/** One rich menu item: colored icon tile + bold title + muted description. */
export function RichMenuItem({
  icon,
  iconClassName,
  title,
  description,
  disabled,
  onSelect,
}: {
  icon: React.ReactNode;
  /** Tailwind classes for the 34px tile (bg + text color, opt. border). */
  iconClassName?: string;
  title: string;
  description: string;
  disabled?: boolean;
  onSelect?: () => void;
}) {
  return (
    <DropdownMenuItem
      onSelect={onSelect}
      disabled={disabled}
      className={cn(
        "items-start gap-3 rounded-[10px] p-2.5",
        disabled && "opacity-45",
      )}
    >
      <span
        className={cn(
          "grid size-[34px] shrink-0 place-items-center rounded-[9px]",
          "[&_svg]:size-[17px]",
          iconClassName,
        )}
        aria-hidden
      >
        {icon}
      </span>
      <span className="min-w-0">
        <span className="block font-semibold text-[13.5px] text-foreground">
          {title}
        </span>
        <span className="mt-0.5 block text-[11.5px] text-muted-foreground leading-snug">
          {description}
        </span>
      </span>
    </DropdownMenuItem>
  );
}

/** Uppercase section label inside a rich menu. */
export function RichMenuSection({ children }: { children: React.ReactNode }) {
  return (
    <div className="px-2.5 pt-2 pb-1.5 font-semibold text-[10.5px] text-muted-foreground uppercase tracking-wide">
      {children}
    </div>
  );
}

/** Footer row with a 7px status dot (green by default) + muted text. The
 *  caller renders its own <DropdownMenuSeparator /> above this footer. */
export function RichMenuFooter({
  children,
  dotClassName,
}: {
  children: React.ReactNode;
  /** Overrides the dot color (default: emerald-500). */
  dotClassName?: string;
}) {
  return (
    <div className="flex items-center gap-2 px-2.5 pt-1.5 pb-1 text-[11.5px] text-muted-foreground">
      <span
        className={cn(
          "size-[7px] shrink-0 rounded-full bg-emerald-500",
          dotClassName,
        )}
        aria-hidden
      />
      <span className="min-w-0 truncate">{children}</span>
    </div>
  );
}
