import { useMemo } from "react";
import type { NavigationId } from "../types";
import type { AppNavigationItem, AppSidebarItemAction } from "../types";

export interface AppSidebarModel {
  navigationItems: AppSidebarItemAction[];
}

interface UseAppSidebarModelInput {
  items: AppNavigationItem[];
  onSelect: (id: NavigationId) => void;
}

export function useAppSidebarModel({ items, onSelect }: UseAppSidebarModelInput): AppSidebarModel {
  const navigationItems = useMemo(
    () =>
      items.map((item) => ({
        ...item,
        onSelect: () => onSelect(item.id),
      })),
    [items, onSelect],
  );

  return {
    navigationItems,
  };
}
