"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

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

var _react = _interopRequireWildcard(require("react"));

var _styledComponents = _interopRequireWildcard(require("styled-components"));

var _lodash = require("lodash");

var _ = require("../../..");

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

var SwatchSection = _styledComponents["default"].div.withConfig({
  displayName: "SwatchSection",
  componentId: "u3lo66-0"
})(["display:flex;flex-wrap:wrap;justify-content:flex-start;"]);

var Swatch = function Swatch(_ref) {
  var name = _ref.name,
      foreground = _ref.foreground,
      background = _ref.background;

  var ColourPaletteSwatchBackground = _styledComponents["default"].div.withConfig({
    displayName: "ColourPaletteSwatchBackground",
    componentId: "u3lo66-1"
  })(["background-color:", ";height:120px;width:200px;display:flex;flex-direction:column;justify-content:center;margin:0 16px 16px 0;"], background);

  var ColourPaletteSwatchText = (0, _styledComponents["default"])(_.Text).withConfig({
    displayName: "ColourPaletteSwatchText",
    componentId: "u3lo66-2"
  })(["text-align:center;color:", ";padding:12px 0;"], foreground);
  return /*#__PURE__*/_react["default"].createElement(ColourPaletteSwatchBackground, null, /*#__PURE__*/_react["default"].createElement(ColourPaletteSwatchText, null, /*#__PURE__*/_react["default"].createElement(_.Span, {
    bold: true
  }, name)), /*#__PURE__*/_react["default"].createElement(ColourPaletteSwatchText, null, background));
};

var Swatches = function Swatches() {
  var theme = (0, _react.useContext)(_styledComponents.ThemeContext);
  var colours = (0, _lodash.map)(theme.colorPalette, function (v, k) {
    return {
      key: k,
      value: v
    };
  }); // For swatch presentation only

  var getForegroundColour = function getForegroundColour(c) {
    var darkForeground = '#403e3d';
    var darkForegroundWhiteLabel = '#333333';
    var fgToBgMap = {
      // Wealthsimple theme
      // too light for white
      '#ffffff': darkForeground,
      '#f9f8f7': darkForeground,
      '#e6e4e3': darkForeground,
      '#bfbdbb': darkForeground,
      '#e5f1f1': '#377674',
      // success
      '#ffebe6': '#ed5a3f',
      // error
      '#fff6e6': '#e69d00',
      // info
      // White label defaults theme
      // too light for white
      '#fafafa': darkForegroundWhiteLabel,
      '#bfbfbf': darkForegroundWhiteLabel,
      '#e6e6e6': darkForegroundWhiteLabel,
      '#fff2ff': '#662966',
      // brand primary bg/fg
      '#e6f7ff': '#1f4e66',
      // brand secondary bg/fg
      '#def2da': '#2a8000',
      // success
      '#ffe6e6': '#e62e2e',
      // error
      '#fff7e6': '#cc8f14' // info

    };
    return fgToBgMap[c] || '#ffffff';
  };

  return /*#__PURE__*/_react["default"].createElement(SwatchSection, null, colours.map(function (colour) {
    return /*#__PURE__*/_react["default"].createElement(Swatch, {
      key: colour.key,
      name: colour.key,
      background: colour.value,
      foreground: getForegroundColour(colour.value)
    });
  }));
};

exports.Swatches = Swatches;