import { titleCase } from "@fern-api/ui-core-utils";
import { FernRegistry } from "../client/generated";
export function computeSubpackages({ endpoints, webhookEndpoints, }) {
    const subpackages = {};
    Object.values({
        ...endpoints,
        ...webhookEndpoints,
    }).forEach((endpoint) => {
        const qualifiedPath = [];
        endpoint.namespace?.forEach((subpackage) => {
            const qualifiedSubpackagePath = [...qualifiedPath, subpackage];
            const fullyQualifiedSubpackageId = FernRegistry.api.v1.SubpackageId(qualifiedSubpackagePath.join("."));
            subpackages[fullyQualifiedSubpackageId] = {
                id: fullyQualifiedSubpackageId,
                name: subpackage,
                displayName: titleCase(subpackage),
            };
            qualifiedPath.push(subpackage);
        });
    });
    return subpackages;
}
