

// hoc/withDockItems.tsx
import type { AppSidebarItemData } from "@/components/sidebar/sidebar-item";
import { useWorkspacePaths } from "@/hooks/use-workspace-paths";
import { PlaneNewIcon } from "@buzzwaretech/propel/icons";
import { observer } from "mobx-react";
import { useParams } from "next/navigation";
import React from "react";

type WithDockItemsProps = {
  dockItems: (AppSidebarItemData & { shouldRender: boolean })[];
};

export function withDockItems<P extends WithDockItemsProps>(
  WrappedComponent: React.ComponentType<P>,
) {
  const ComponentWithDockItems = observer(function ComponentWithDockItems(
    props: Omit<P, keyof WithDockItemsProps>,
  ) {
    const { workspaceSlug } = useParams();
    const { isProjectsPath, isNotificationsPath } = useWorkspacePaths();

    const dockItems: (AppSidebarItemData & { shouldRender: boolean })[] = [
      {
        label: "Projects",
        icon: <PlaneNewIcon className="size-5" />,
        href: `/${workspaceSlug}/`,
        isActive: isProjectsPath && !isNotificationsPath,
        shouldRender: true,
      },
    ];

    return <WrappedComponent {...(props as P)} dockItems={dockItems} />;
  });

  return ComponentWithDockItems;
}
