import Cookies from "js-cookie";

const deleteCookies = (name) => {
  const date = new Date();
  date.setHours(date.getHours() - 1);
  const { host } = window.location;
  const env = host.includes("localhost")
    ? "local"
    : host.includes("test") || host.includes("staging")
    ? "staging"
    : "production";
  if (env === "staging") {
    Cookies.remove(name, {
      domain: window.location.hostname?.includes("ca")
        ? ".learngual.ca"
        : ".learngual.com",
      expires: date,
      path: "/",
    });
  } else if (env === "local") {
    Cookies.remove(name, {
      domain: "localhost",
      expires: date,
      path: "/",
    });
  } else {
    Cookies.remove(name, {
      domain: window.location.hostname?.includes("ca")
        ? ".learngual.ca"
        : ".learngual.com",
      expires: date,
      path: "/",
    });
  }
};

export default deleteCookies;
