import { createTypedReducerWithImmer } from "@insite/client-framework/Common/CreateTypedReducer";
import OnePageCheckoutConfirmationState from "@insite/client-framework/Store/Pages/OnePageCheckoutConfirmation/OnePageCheckoutConfirmationState";
import { Draft } from "immer";

const initialState: OnePageCheckoutConfirmationState = {
    isPreloadingData: false,
};

const reducer = {
    "Pages/OnePageCheckoutConfirmation/BeginLoadCart": (
        draft: Draft<OnePageCheckoutConfirmationState>,
        action: { cartId: string },
    ) => {
        draft.cartId = action.cartId;
    },
    "Pages/OnePageCheckoutConfirmation/SetIsPreloadingData": (
        draft: Draft<OnePageCheckoutConfirmationState>,
        action: { isPreloadingData: boolean },
    ) => {
        draft.isPreloadingData = action.isPreloadingData;
    },
};

export default createTypedReducerWithImmer(initialState, reducer);
