import { FEAGlobals } from "../../../../../../common/Globals";
const isTypeMutedForSource = (source, type, muteFilters) => muteFilters.filter((mFilter) => mFilter.source === source && mFilter.type === type);
export const loadSources = async (setNotificationSources, setReloadSources) => {
    const notificationSources = await FEAGlobals.FSBL.Clients.NotificationClient.getSources();
    const muteFilters = await FEAGlobals.FSBL.Clients.NotificationClient.getMuteFilters();
    const componentsConfigPath = "finsemble.components";
    const notificationsTypesPath = "finsemble.servicesConfig.notifications.types";
    const { err, data } = await FEAGlobals.FSBL.Clients.ConfigClient.getMultiple([
        componentsConfigPath.split("."),
        notificationsTypesPath.split("."),
    ]);
    const componentsConfig = data[componentsConfigPath];
    const notificationsTypes = data[notificationsTypesPath];
    if (err) {
        console.error("Error getting components config to extract notifications config");
    }
    else {
        const configuredTypes = Object.keys(notificationsTypes);
        let sources = null;
        if (notificationSources) {
            sources = notificationSources.map((currSource) => {
                var _a, _b, _c, _d;
                const types = configuredTypes.map((configuredType) => Object({
                    name: configuredType,
                    muted: isTypeMutedForSource(currSource, configuredType, muteFilters).length > 0,
                }));
                const result = {
                    source: currSource,
                    icon: ((_d = (_c = (_b = (_a = componentsConfig[currSource]) === null || _a === void 0 ? void 0 : _a.foreign) === null || _b === void 0 ? void 0 : _b.components) === null || _c === void 0 ? void 0 : _c.Toolbar) === null || _d === void 0 ? void 0 : _d.iconURL) || null,
                    types,
                };
                return result;
            });
            setNotificationSources(sources);
            setReloadSources(false);
        }
    }
};
export const getNotificationsPreferences = async () => await FEAGlobals.FSBL.Clients.NotificationClient.getPreferences();
//# sourceMappingURL=notificationViewsUtils.js.map