"use strict";

const React = require("react");
const util = require("util");
const ansiHTML = require("ansi-html-community");
// const entities = require("entities");

function escape(input) {
	// NOTE: This is not necessarily secure! This is just a stopgap solution (used in development-mode code only) to not break display of < and > characters until we can figure out why `entities` doesn't combine with `ansi-html-community`.
	return input.replace(/</g, "&lt;").replace(/>/g, "&gt;");
}

module.exports = function DebugView({ value }) {
	if (process.env.NODE_ENV !== "development") {
		return "[Debug view is disabled outside of development mode. If you see this, please contact the administrator.]";
	} else {
		let inspected = util.inspect(value, { colors: true, depth: null });
		return <pre className="debugPrint" dangerouslySetInnerHTML={{ __html: ansiHTML(escape(inspected)) }} />;
	}
};
