import { Link } from "react-router-dom";
import {
  SidebarMenuButton,
  SidebarMenuItem,
} from "@/components/ui/sidebar";

export type MenuItemKind = "link" | "fresh-registration";

export interface MenuItemDescriptor {
  title: string;
  icon: React.ComponentType<{ className?: string }>;
  kind: MenuItemKind;
  url: string;
}

interface ApplicantSidebarMenuItemProps {
  item: MenuItemDescriptor;
  pathname: string;
  onFreshRegistration: () => void;
}

export function ApplicantSidebarMenuItem({
  item,
  pathname,
  onFreshRegistration,
}: ApplicantSidebarMenuItemProps) {
  const Icon = item.icon;
  const active = pathname === item.url;

  if (item.kind === "fresh-registration") {
    return (
      <SidebarMenuItem>
        <SidebarMenuButton
          onClick={onFreshRegistration}
          tooltip={item.title}
          isActive={active}
          className="cursor-pointer"
        >
          <Icon className="h-4 w-4" />
          <span>{item.title}</span>
        </SidebarMenuButton>
      </SidebarMenuItem>
    );
  }

  return (
    <SidebarMenuItem>
      <SidebarMenuButton asChild isActive={active} tooltip={item.title}>
        <Link to={item.url} className="flex mt-4 w-full items-center gap-2">
          <Icon className="h-4 w-4 shrink-0" />
          <span className="truncate">{item.title}</span>
        </Link>
      </SidebarMenuButton>
    </SidebarMenuItem>
  );
}
