import { jsx as _jsx } from "react/jsx-runtime";
import { DashboardParameterModeValues, isIdentifierRef } from "@gooddata/sdk-model";
import { ParameterPicker } from "@gooddata/sdk-ui-kit";
import { useDashboardDispatch, useDashboardSelector } from "../../../model/react/DashboardStoreProvider.js";
import { selectCatalogParameters, selectCatalogParametersStatus, } from "../../../model/store/catalog/catalogSelectors.js";
import { parametersActions } from "../../../model/store/parameters/index.js";
import { selectActiveParameterRefKeys } from "../../../model/store/parameters/parametersSelectors.js";
const PICKER_MAX_LIST_HEIGHT = 320;
/**
 * Connected wrapper around sdk-ui-kit's `ParameterPicker`.
 *
 * @internal
 */
export function DashboardParameterPicker({ onAdd, onCancel }) {
    const dispatch = useDashboardDispatch();
    const parameters = useDashboardSelector(selectCatalogParameters);
    const status = useDashboardSelector(selectCatalogParametersStatus);
    const excludedKeys = useDashboardSelector(selectActiveParameterRefKeys);
    const isLoading = status === "loading" || status === "uninitialized";
    return (_jsx(ParameterPicker, { parameters: parameters, excludedKeys: excludedKeys, isLoading: isLoading, maxListHeight: PICKER_MAX_LIST_HEIGHT, onAdd: (selected) => {
            for (const { ref, definition } of selected) {
                if (!isIdentifierRef(ref)) {
                    continue;
                }
                dispatch(parametersActions.addParameter({
                    parameter: {
                        ref,
                        parameterType: "NUMBER",
                        mode: DashboardParameterModeValues.ACTIVE,
                    },
                    workspaceDefault: definition.defaultValue,
                }));
            }
            onAdd?.();
        }, onCancel: () => onCancel?.() }));
}
//# sourceMappingURL=DashboardParameterPicker.js.map