import { setCookie } from "@insite/client-framework/Common/Cookies";
import { createHandlerChainRunner, Handler } from "@insite/client-framework/HandlerCreator";

export const ShowInventoryCookieName = "ShowInventory";

interface Parameter {
    showInventory: boolean;
}

type HandlerType = Handler<Parameter>;

export const SetCookie: HandlerType = props => {
    setCookie(ShowInventoryCookieName, props.parameter.showInventory.toString());
};

export const DispatchSetShowInventory: HandlerType = props => {
    props.dispatch({
        type: "Context/SetShowInventory",
        showInventory: props.parameter.showInventory,
    });
};

export const chain = [SetCookie, DispatchSetShowInventory];

const setShowInventory = createHandlerChainRunner(chain, "setShowInventory");
export default setShowInventory;
