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 = [];
        return endpoint.namespace?.forEach((subpackage) => {
            const prunedSubpackage = subpackage.replace(/subpackage_/, "");
            const qualifiedSubpackagePath = [...qualifiedPath, prunedSubpackage];
            const fullyQualifiedSubpackageId = FernRegistry.api.v1.SubpackageId(`subpackage_${qualifiedSubpackagePath.join(".")}`);
            subpackages[fullyQualifiedSubpackageId] = {
                id: fullyQualifiedSubpackageId,
                name: qualifiedSubpackagePath.join("/"),
                displayName: titleCase(prunedSubpackage),
            };
            qualifiedPath.push(prunedSubpackage);
        });
    });
    return subpackages;
}
