import { createTypedReducerWithImmer } from "@insite/client-framework/Common/CreateTypedReducer";
import ShareListDetailModalState from "@insite/client-framework/Store/Components/ShareListDetailModal/ShareListDetailModalState";
import { Draft } from "immer";

const initialState: ShareListDetailModalState = {
    isOpen: false,
};

const reducer = {
    "Components/ShareListDetailModal/CompleteSetIsOpen": (
        draft: Draft<ShareListDetailModalState>,
        action: {
            isOpen: boolean;
            listOwner?: string;
        },
    ) => {
        draft.isOpen = action.isOpen;
        if (action.isOpen) {
            draft.listOwner = action.listOwner;
        }
    },
};

export default createTypedReducerWithImmer(initialState, reducer);
