// (C) 2023-2025 GoodData Corporation
import { defineMessages } from "react-intl";
const messages = defineMessages({
    searchDataSourceError: { id: "userManagement.dataSource.searchError" },
});
const createErrorOption = (intl) => {
    return [
        {
            isDisabled: true,
            type: "error",
            label: intl.formatMessage(messages.searchDataSourceError),
        },
    ];
};
export const loadUserDataSourceOptionsPromise = (backend, intl) => async (inputValue) => {
    try {
        const dataSources = await backend.dataSources().getDataSourceIdentifiers();
        return dataSources
            .filter((ds) => ds.name.toLocaleLowerCase().includes(inputValue.toLowerCase()))
            .sort((itemA, itemB) => {
            const textA = itemA.name.toUpperCase();
            const textB = itemB.name.toUpperCase();
            return textA.localeCompare(textB);
        })
            .map((dataSource) => ({
            label: dataSource.id,
            value: dataSource,
        }));
    }
    catch {
        return createErrorOption(intl);
    }
};
//# sourceMappingURL=loadUserDataSourceOptionsPromise.js.map