"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.isStyleCacheProvider = exports.isFlexibleUiTitleBlock = exports.isFlexibleUiPreviewBlock = exports.isFlexibleUiFooterBlock = exports.isFlexibleUiElement = exports.isFlexibleUiCard = exports.isFlexibleUiBlock = void 0;
var _react = _interopRequireDefault(require("react"));
var _blocks = _interopRequireWildcard(require("../view/FlexibleCard/components/blocks"));
var Blocks = _blocks;
var Elements = _interopRequireWildcard(require("../view/FlexibleCard/components/elements"));
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
var isFlexibleUiCard = exports.isFlexibleUiCard = function isFlexibleUiCard(children, ui) {
  if (ui !== null && ui !== void 0 && ui.removeBlockRestriction) {
    var _React$Children$toArr;
    return children && ((_React$Children$toArr = _react.default.Children.toArray(children)) === null || _React$Children$toArr === void 0 ? void 0 : _React$Children$toArr.length) > 0 ? true : false;
  }
  if (children && _react.default.Children.toArray(children).some(function (child) {
    return _isFlexibleUiTitleBlock(child);
  })) {
    return true;
  }
  return false;
};
var isStyleCacheProvider = exports.isStyleCacheProvider = function isStyleCacheProvider(node) {
  var _node$type, _node$type2;
  if (typeof node.type !== 'string' && ((_node$type = node.type) === null || _node$type === void 0 ? void 0 : _node$type.name) === 'StyleCacheProvider' && node.props.children) {
    return true;
  } else if (typeof node.type !== 'string' && ((_node$type2 = node.type) === null || _node$type2 === void 0 ? void 0 : _node$type2.name) === 'CC' && node.props.children) {
    return true;
  }
  return false;
};
var _isFlexibleUiBlock = exports.isFlexibleUiBlock = function isFlexibleUiBlock(node) {
  if (! /*#__PURE__*/_react.default.isValidElement(node)) {
    return false;
  }
  if (isStyleCacheProvider(node)) {
    // Component wrapped with compiled at runtime, check for children
    var isChildrenValid = true;
    _react.default.Children.map(node.props.children, function (child) {
      var _child$type;
      if (! /*#__PURE__*/_react.default.isValidElement(child)) {
        isChildrenValid = false;
        return;
      }
      if (typeof child.type !== 'string' && ((_child$type = child.type) === null || _child$type === void 0 ? void 0 : _child$type.name) !== 'Style') {
        isChildrenValid = _isFlexibleUiBlock(child);
      }
    });
    return isChildrenValid;
  }
  if (Object.values(Blocks).some(function (type) {
    return type === node.type;
  })) {
    return true;
  }
  return false;
};
var _isFlexibleUiElement = exports.isFlexibleUiElement = function isFlexibleUiElement(node) {
  if (! /*#__PURE__*/_react.default.isValidElement(node)) {
    return false;
  }
  if (Object.values(Elements).some(function (type) {
    return type === node.type;
  })) {
    return true;
  }
  if (isStyleCacheProvider(node)) {
    // Component wrapped with compiled at runtime, check for children
    var isChildrenValid = true;
    _react.default.Children.map(node.props.children, function (child) {
      var _child$type2;
      if (! /*#__PURE__*/_react.default.isValidElement(child)) {
        isChildrenValid = false;
        return;
      }
      if (typeof child.type !== 'string' && ((_child$type2 = child.type) === null || _child$type2 === void 0 ? void 0 : _child$type2.name) !== 'Style') {
        isChildrenValid = _isFlexibleUiElement(child);
      }
    });
    return isChildrenValid;
  }
  return false;
};
var _isFlexibleUiTitleBlock = exports.isFlexibleUiTitleBlock = function isFlexibleUiTitleBlock(node) {
  if (! /*#__PURE__*/_react.default.isValidElement(node)) {
    return false;
  }
  if (node.type === _blocks.TitleBlock) {
    return true;
  }
  if (isStyleCacheProvider(node)) {
    // Component wrapped with compiled at runtime, check for children
    var isChildrenValid = true;
    _react.default.Children.map(node.props.children, function (child) {
      var _child$type3;
      if (! /*#__PURE__*/_react.default.isValidElement(child)) {
        isChildrenValid = false;
        return;
      }
      if (typeof child.type !== 'string' && ((_child$type3 = child.type) === null || _child$type3 === void 0 ? void 0 : _child$type3.name) !== 'Style') {
        isChildrenValid = _isFlexibleUiTitleBlock(child);
      }
    });
    return isChildrenValid;
  }
  return false;
};
var _isFlexibleUiPreviewBlock = exports.isFlexibleUiPreviewBlock = function isFlexibleUiPreviewBlock(node) {
  if (! /*#__PURE__*/_react.default.isValidElement(node)) {
    return false;
  }
  if (node.type === _blocks.PreviewBlock) {
    return true;
  }
  if (isStyleCacheProvider(node)) {
    // Component wrapped with compiled at runtime, check for children
    var isChildrenValid = true;
    _react.default.Children.map(node.props.children, function (child) {
      var _child$type4;
      if (! /*#__PURE__*/_react.default.isValidElement(child)) {
        isChildrenValid = false;
        return;
      }
      if (typeof child.type !== 'string' && ((_child$type4 = child.type) === null || _child$type4 === void 0 ? void 0 : _child$type4.name) !== 'Style') {
        isChildrenValid = _isFlexibleUiPreviewBlock(child);
      }
    });
    return isChildrenValid;
  }
  return false;
};
var isFlexibleUiFooterBlock = exports.isFlexibleUiFooterBlock = function isFlexibleUiFooterBlock(node) {
  return /*#__PURE__*/_react.default.isValidElement(node) && node.type === _blocks.FooterBlock;
};