import { mockBackendMenus } from "@/constants/menu";
import type { BackendMenuResponse, UserMenuResponse } from "@/types/menu";

const mapMenus = (menus: BackendMenuResponse[]): UserMenuResponse[] =>
  menus
    .sort((a, b) => a.order_index - b.order_index)
    .map((menu) => ({
      title: menu.title,
      path: menu.path,
      type: menu.menu_type === "link" ? "external" : "internal",
      externalUrl: menu.menu_type === "link" ? menu.path : undefined,
      icon: menu.icon,
      sort: menu.order_index,
      children: mapMenus(menu.children || [])
    }));

export async function getUserMenus(): Promise<UserMenuResponse[]> {
  return Promise.resolve(mapMenus(mockBackendMenus));
}
