"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.createWhitelabelTheme = exports._getColorPaletteOverrides = exports._generateAuxColors = exports._generateBrandColors = exports._whiteLabelShadingValues = void 0;

var _color = _interopRequireDefault(require("color"));

var _whitelabelDefaults = require("./whitelabel-defaults.theme");

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; }

/**
 * These are the magic values for darkening and lightening
 */
var _whiteLabelShadingValues = {
  dark: 0.3,
  fg: 0.5,
  bg: 0.5
};
/**
 * Generates colours with brand naming conventions for PatchworkTheme.colorPalette
 */

exports._whiteLabelShadingValues = _whiteLabelShadingValues;

var _generateBrandColors = function _generateBrandColors(brandKeyword, color) {
  var _ref;

  return brandKeyword === undefined || color === undefined || color === null ? {} : (_ref = {}, _defineProperty(_ref, "brand-".concat(brandKeyword, "-base"), color), _defineProperty(_ref, "brand-".concat(brandKeyword, "-dark"), (0, _color["default"])(color).darken(_whiteLabelShadingValues.dark).hex()), _defineProperty(_ref, "brand-".concat(brandKeyword, "-fg"), (0, _color["default"])(color).darken(_whiteLabelShadingValues.fg).hex()), _defineProperty(_ref, "brand-".concat(brandKeyword, "-bg"), (0, _color["default"])(color).lighten(_whiteLabelShadingValues.bg).hex()), _ref);
};

exports._generateBrandColors = _generateBrandColors;

var _generateAuxColors = function _generateAuxColors(color) {
  return color === undefined ? {} : {
    'aux-1': (0, _color["default"])(color).lighten(_whiteLabelShadingValues.bg).hex(),
    'aux-2': color,
    'aux-3': (0, _color["default"])(color).darken(_whiteLabelShadingValues.dark).hex(),
    'aux-4': (0, _color["default"])(color).darken(_whiteLabelShadingValues.fg).hex()
  };
};
/**
 * When given a base colorPalette, generates shades of primary and secondary colour overrides
 * @param {PatchworkTheme.colorPalette} colorPalette
 * @param {String} primary
 * @param {String} secondary
 */


exports._generateAuxColors = _generateAuxColors;

var _getColorPaletteOverrides = function _getColorPaletteOverrides(colorPalette, primary, secondary) {
  return _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, colorPalette), _generateAuxColors(primary)), _generateBrandColors('primary', primary)), _generateBrandColors('secondary', secondary));
};

exports._getColorPaletteOverrides = _getColorPaletteOverrides;

var createWhitelabelTheme = function createWhitelabelTheme(_ref2) {
  var primary = _ref2.primary,
      secondary = _ref2.secondary,
      name = _ref2.name,
      buttonBorderRadius = _ref2.buttonBorderRadius;

  var newTheme = _objectSpread({}, _whitelabelDefaults.whitelabelDefaults);

  var newColorPalette = _getColorPaletteOverrides(_whitelabelDefaults.whitelabelDefaults.colorPalette, primary, secondary);

  newTheme.name = name;
  newTheme.colorPalette = newColorPalette;

  if (buttonBorderRadius != null) {
    newTheme.buttonBorderRadius = buttonBorderRadius;
  }

  return newTheme;
};

exports.createWhitelabelTheme = createWhitelabelTheme;