import { apiGet } from "./client";
import { TENANT_DOMAIN } from "./config";
import type { ApiCategory, CategoriesResponse } from "./types";

export async function getProductCategories(): Promise<ApiCategory[]> {
  const data = await apiGet<CategoriesResponse>(
    `/tenants/${TENANT_DOMAIN}/categories?entityType=product`,
  );

  return [...data.items]
    .filter((category) => category.isActive && category.parentId === null)
    .sort((a, b) => a.sortOrder - b.sortOrder);
}
