import {createSlice} from "@reduxjs/toolkit";

export type FilterState = {
    sorting: string;
    shippingWarehouseId: number;
}

export interface FilterSliceState {
    visible: boolean;
    state: FilterState
}

const initialState: FilterSliceState = {
    visible: false,
    state: {
        sorting: 'shipment_date_desc',
        shippingWarehouseId: -1,
    }
}

export const filterSlice = createSlice({
    name: 'filter',
    initialState,
    reducers: {
        openFilter: (state) => {
            state.visible = true;
        },
        closeFilter: (state) => {
            state.visible = false;
        },
        setFilterState: (state, action) => {
            state.state = action.payload;
        },
    },
})

export const {openFilter, closeFilter, setFilterState} = filterSlice.actions;
export default filterSlice.reducer;