"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.DefaultTextEditorStateProvider = exports.DefaultCanvasStateProvider = exports.DefaultCanvasProvider = void 0;
var _react = _interopRequireDefault(require("react"));
var _reactRedux = require("react-redux");
var _CanvasProvider = require("redhotmagma-graphics-editor/CanvasInterface/CanvasProvider");
var _TextEditorStateProvider = require("redhotmagma-graphics-editor/Components/TextEditor/TextEditorStateProvider");
var _withActiveCanvas = require("../../Modules/Designer/withActiveCanvas");
var _Selectors = require("../../Reducers/DesignArea/Selectors");
var _get = _interopRequireDefault(require("lodash/get"));
var _first = _interopRequireDefault(require("lodash/first"));
var _createSelector = _interopRequireDefault(require("../../../Utils/Function/createSelector"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
var DefaultCanvasProvider = exports.DefaultCanvasProvider = (0, _withActiveCanvas.withActiveCanvas)(function (_ref) {
  var canvas = _ref.canvas,
    children = _ref.children;
  return /*#__PURE__*/_react["default"].createElement(_CanvasProvider.CanvasProvider, {
    canvas: canvas
  }, children);
});
var DefaultCanvasStateProvider = exports.DefaultCanvasStateProvider = (0, _withActiveCanvas.withActiveCanvas)(function (_ref2) {
  var canvas = _ref2.canvas,
    children = _ref2.children;
  return /*#__PURE__*/_react["default"].createElement(_CanvasProvider.CanvasStateProvider, {
    canvas: canvas
  }, children);
});
var createDefaultStyle = (0, _createSelector["default"])(function (_ref3) {
  var fonts = _ref3.fonts;
  return fonts;
}, _Selectors.getColorPalettes, function (fonts, colorPalettes) {
  var fontFamily = '';
  var colorValue = '';
  var colorIdentifier = '';
  var colorPaleteIdentifier = '';
  var firstColorPalette = (0, _first["default"])(colorPalettes);
  var colors = (0, _get["default"])(firstColorPalette, 'colors', []);
  var firstColor = (0, _first["default"])(colors);
  var firstFont = (0, _first["default"])(fonts);
  if (firstColorPalette && firstFont) {
    colorValue = '#' + (0, _get["default"])(firstColor, 'hex_value', '000000');
    colorIdentifier = (0, _get["default"])(firstColor, 'identifier', 'black');
    colorPaleteIdentifier = (0, _get["default"])(firstColorPalette, 'identifier', 'default');
    var escapeQuotes = function escapeQuotes(str) {
      return str.replace(/(['"])/g, '\\$1');
    };
    fontFamily = "\"".concat(escapeQuotes(firstFont.family), "\"");
  }
  return {
    color: {
      value: colorValue,
      identifier: "{\"color\": \"".concat(colorIdentifier, "\", \"palette\": \"").concat(colorPaleteIdentifier, "\"}")
    },
    fontSize: '16px',
    fontFamily: fontFamily
  };
});
var mapStateToProps = function mapStateToProps(state) {
  return {
    defaultStyle: createDefaultStyle(state)
  };
};
var DefaultTextEditorStateProvider = exports.DefaultTextEditorStateProvider = (0, _reactRedux.connect)(mapStateToProps)(_TextEditorStateProvider.TextEditorStateProvider);