"use client";

import React from "react";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { cn } from "@/lib/utils";

export default function SidebarItem({
  name,
  logo,
  path,
  className,
  linkClassName,
  style,
  collapseButton,
  right = null,
}: {
  name: string;
  logo: React.ReactNode;
  path: string;
  style?: React.CSSProperties;
  className?: string;
  linkClassName?: string;
  right?: React.ReactNode;
  collapseButton?: React.ReactNode;
}) {
  const currentPath = usePathname();
  return (
    <li
      className={cn(
        "relative flex justify-between rounded-lg hover:bg-accent",
        path == currentPath ? "bg-accent/50" : "",
        className,
      )}
      style={style}
    >
      <div className="flex-1">
        {collapseButton}
        <Link
          href={path}
          className={cn(
            "flex items-center gap-x-2 rounded-[inherit] px-3 py-2",
            linkClassName,
          )}
        >
          {logo}
          <span title={name} className="line-clamp-1 break-all">
            {name}
          </span>
        </Link>
      </div>
      {right}
    </li>
  );
}
