// (C) 2021-2026 GoodData Corporation
const setCatalogItems = (state, action) => {
    const { attributes, measures, dateDatasets, facts, attributeHierarchies, dateHierarchyTemplates } = action.payload;
    state.attributes = attributes;
    state.measures = measures;
    state.facts = facts;
    state.dateDatasets = dateDatasets;
    state.attributeHierarchies = attributeHierarchies;
    state.dateHierarchyTemplates = dateHierarchyTemplates;
};
const setCatalogMeasuresAndFacts = (state, action) => {
    const { measures, facts } = action.payload;
    state.measures = measures;
    state.facts = facts;
};
const addAttributeHierarchy = (state, action) => {
    const attributeHierarchy = action.payload;
    state.attributeHierarchies = [...(state.attributeHierarchies ?? []), attributeHierarchy];
};
const updateAttributeHierarchy = (state, action) => {
    const attributeHierarchy = action.payload;
    const updatingIndex = state.attributeHierarchies?.findIndex((it) => it.attributeHierarchy.id === attributeHierarchy.attributeHierarchy.id) ?? -1;
    if (updatingIndex >= 0) {
        state.attributeHierarchies = [...(state.attributeHierarchies ?? [])];
        state.attributeHierarchies.splice(updatingIndex, 1, attributeHierarchy);
    }
};
const deleteAttributeHierarchy = (state, action) => {
    const attributeHierarchy = action.payload;
    state.attributeHierarchies = state.attributeHierarchies?.filter((it) => it.attributeHierarchy.id !== attributeHierarchy.attributeHierarchy.id);
};
const setCatalogParameters = (state, action) => {
    state.parameters = action.payload;
};
export const catalogReducers = {
    setCatalogItems,
    setCatalogMeasuresAndFacts,
    addAttributeHierarchy,
    updateAttributeHierarchy,
    deleteAttributeHierarchy,
    setCatalogParameters,
};
//# sourceMappingURL=catalogReducers.js.map