import { jsx as _jsx } from "react/jsx-runtime";
// (C) 2025-2026 GoodData Corporation
import { createContext, useContext, useState } from "react";
import { invariant } from "ts-invariant";
import { useCancelablePromise } from "@gooddata/sdk-ui";
import { useAutomationService } from "../useAutomationService.js";
const FilterOptionsContext = createContext(null);
export function FilterOptionsProvider({ children, scope }) {
    const [workspaceUsers, setWorkspaceUsers] = useState([]);
    const [dashboards, setDashboards] = useState([]);
    const [workspaces, setWorkspaces] = useState([]);
    const { promiseGetUsers, promiseGetDashboards, promiseGetWorkspaces } = useAutomationService(scope);
    const { status: workspaceUsersStatus } = useCancelablePromise({
        promise: async () => {
            return promiseGetUsers();
        },
        onSuccess: (result) => {
            setWorkspaceUsers(result);
        },
        onError: (error) => {
            console.error(error);
        },
    }, [promiseGetUsers]);
    const { status: dashboardsStatus } = useCancelablePromise({
        promise: async () => {
            return promiseGetDashboards();
        },
        onSuccess: (result) => {
            setDashboards(result);
        },
        onError: (error) => {
            console.error(error);
        },
    }, [promiseGetDashboards]);
    const { status: workspacesStatus } = useCancelablePromise({
        promise: async () => {
            return promiseGetWorkspaces();
        },
        onSuccess: (result) => {
            setWorkspaces(result);
        },
        onError: (error) => {
            console.error(error);
        },
    }, [promiseGetWorkspaces]);
    const wokspaceUsersLoading = workspaceUsersStatus === "loading";
    const dashboardsLoading = dashboardsStatus === "loading";
    const workspacesLoading = workspacesStatus === "loading";
    const contextValue = {
        workspaceUsers,
        dashboards,
        wokspaceUsersLoading,
        dashboardsLoading,
        workspaces,
        workspacesLoading,
    };
    return _jsx(FilterOptionsContext.Provider, { value: contextValue, children: children });
}
export const useFilterOptions = () => {
    const context = useContext(FilterOptionsContext);
    invariant(context, "FilterOptionsContext not found");
    return context;
};
//# sourceMappingURL=FilterOptionsContext.js.map