"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 _color = _interopRequireDefault(require("color"));

var _lodash = require("lodash");

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

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

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 ColourPaletteSwatchBackground = (0, _styledComponents["default"])(_.Box).withConfig({
  displayName: "ColourPaletteSwatchBackground",
  componentId: "u3lo66-1"
})(["height:120px;width:200px;"]);

var Swatch = function Swatch(_ref) {
  var name = _ref.name,
      hexCode = _ref.hexCode;
  var foregroundName = new _color["default"](hexCode).isLight() ? 'greyscale-black' : 'white';
  return /*#__PURE__*/_react["default"].createElement(ColourPaletteSwatchBackground, {
    colorName: name,
    stacked: "column",
    justify: "center",
    align: "center",
    spacing: ['mr1', 'mb1']
  }, /*#__PURE__*/_react["default"].createElement(_.Text, {
    bold: true,
    colorName: foregroundName,
    spacing: ['pv1', 'ph0']
  }, name), /*#__PURE__*/_react["default"].createElement(_.Text, {
    colorName: foregroundName
  }, hexCode));
};

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
    };
  });
  return /*#__PURE__*/_react["default"].createElement(SwatchSection, null, colours.map(function (colour) {
    return /*#__PURE__*/_react["default"].createElement(Swatch, {
      key: colour.key,
      name: colour.key,
      hexCode: colour.value
    });
  }));
};

exports.Swatches = Swatches;