"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.EnvTag = void 0;

var _preact = require("preact");

var _classnames = _interopRequireDefault(require("classnames"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

const classMap = {
  dev: 'bg-yellow black',
  stage: 'bg-green black'
};
const fallback = 'bg-red white';

const guessEnv = () => {
  let host = 'server';

  try {
    host = window.location.host;
  } catch (err) {// ignore
  }

  if (host.includes('dev')) {
    return 'dev';
  }

  if (host.includes('stage')) {
    return 'stage';
  }

  if (host.includes('localhost')) {
    return 'local';
  }

  return 'prod';
};

const EnvTag = ({
  env,
  style
}) => {
  env = env || guessEnv();

  if (!env || env === 'prod' || env === 'production') {
    return null;
  }

  if (env === 'development') {
    env = 'dev';
  }

  return (0, _preact.h)("div", {
    style: _objectSpread({
      right: '0px',
      top: '0px',
      padding: '4px',
      fontSize: '10px',
      borderBottomLeftRadius: '4px'
    }, style),
    className: (0, _classnames.default)('absolute z-999 br--bottom-left fw6', classMap[env] || fallback)
  }, env.toUpperCase());
};

exports.EnvTag = EnvTag;