const isProduction = import.meta.env.PROD;

// not replacing newlines (which \s does)
const spacesAndTabs = /[ \t]{2,}/g;
const lineStartWithSpaces = /^[ \t]*/gm;

// using .trim() to clear the any newlines before the first text and after last text
const clean = (value) => value.replace(spacesAndTabs, " ").replace(lineStartWithSpaces, "").trim();
const getDevMessage = (message) =>
  clean(`
  %creact-beautiful-dnd

  %c${clean(message)}

  %c👷‍ This is a development only message. It will be removed in production builds.
`);
export const getFormattedMessage = (message) => [
  getDevMessage(message),
  // title (green400)
  "color: #00C584; font-size: 1.2em; font-weight: bold;",
  // message
  "line-height: 1.5",
  // footer (purple300)
  "color: #723874;"
];
const isDisabledFlag = "__react-beautiful-dnd-disable-dev-warnings";

export function log(type, message) {
  // no warnings in production
  if (isProduction) {
    return;
  }

  // manual opt out of warnings
  if (typeof window !== "undefined" && window[isDisabledFlag]) {
    return;
  }

  console[type](...getFormattedMessage(message));
}

export const warning = log.bind(null, "warn");
export const error = log.bind(null, "error");
