export default class StatusPageResourceUtil {
    /**
     * Formats an array of StatusPageResource items into a string grouped by their resource group.
     *
     * If resources have no group or only one resource exists without a group, returns a simple comma-separated list.
     * If resources are grouped, returns a formatted string like:
     * "EU: Infrastructure, Website; UK: Infrastructure, API"
     *
     * @param resources - Array of StatusPageResource items with displayName, statusPageGroupId, and optionally statusPageGroup.name
     * @param defaultValue - Value to return if no resources (defaults to "None")
     * @returns Formatted string of resources grouped by their resource group
     */
    static getResourcesGroupedByGroupName(resources, defaultValue = "") {
        var _a;
        if (!resources || resources.length === 0) {
            return defaultValue;
        }
        // Check if any resource has a group
        const hasAnyGroup = resources.some((r) => {
            return r.statusPageGroupId || r.statusPageGroup;
        });
        // If no resources have groups, return simple comma-separated list
        if (!hasAnyGroup) {
            return (resources
                .map((r) => {
                return r.displayName;
            })
                .filter((name) => {
                return name;
            })
                .join(", ") || "");
        }
        // Group resources by their group name
        const resourcesByGroup = {};
        const ungroupedResources = [];
        for (const resource of resources) {
            const displayName = resource.displayName;
            if (!displayName) {
                continue;
            }
            const groupName = ((_a = resource.statusPageGroup) === null || _a === void 0 ? void 0 : _a.name) || undefined;
            if (groupName) {
                if (!resourcesByGroup[groupName]) {
                    resourcesByGroup[groupName] = [];
                }
                resourcesByGroup[groupName].push(displayName);
            }
            else {
                ungroupedResources.push(displayName);
            }
        }
        // Build the formatted string
        const formattedGroups = [];
        // Add grouped resources
        for (const groupName in resourcesByGroup) {
            const groupResources = resourcesByGroup[groupName];
            formattedGroups.push(`${groupName}: ${groupResources.join(", ")}`);
        }
        // Add ungrouped resources on separate lines (without "Other" label)
        if (ungroupedResources.length > 0) {
            for (const resourceName of ungroupedResources) {
                formattedGroups.push(resourceName);
            }
        }
        return formattedGroups.join("<br/>") || defaultValue;
    }
}
//# sourceMappingURL=StatusPageResource.js.map