// (C) 2022-2026 GoodData Corporation
import { useMemo } from "react";
import { invariant } from "ts-invariant";
import { dashboardAttributeFilterItemDisplayForm, dashboardAttributeFilterItemLocalIdentifier, dashboardAttributeFilterItemTitle, } from "@gooddata/sdk-model";
/**
 * @internal
 */
export function useOriginalConfigurationState(neighborFilters, filterElementsBy) {
    return useMemo(() => {
        return neighborFilters.map((neighborFilter) => {
            const neighborFilterLocalId = dashboardAttributeFilterItemLocalIdentifier(neighborFilter);
            const neighborFilterDisplayForm = dashboardAttributeFilterItemDisplayForm(neighborFilter);
            const neighborFilterTitle = dashboardAttributeFilterItemTitle(neighborFilter);
            const isSelected = filterElementsBy?.some((by) => by.filterLocalIdentifier === neighborFilterLocalId) || false;
            const overAttributes = filterElementsBy?.find((by) => by.filterLocalIdentifier === neighborFilterLocalId)?.over.attributes;
            invariant(neighborFilterLocalId, "Cannot initialize the attribute filter configuration panel, neighbor filter has missing 'localIdentifier' property.");
            return {
                localIdentifier: neighborFilterLocalId,
                displayForm: neighborFilterDisplayForm,
                isSelected,
                overAttributes: overAttributes,
                selectedConnectingAttribute: overAttributes?.[0],
                title: neighborFilterTitle,
            };
        });
    }, [neighborFilters, filterElementsBy]);
}
