import React from 'react';
import * as Blocks from '../view/FlexibleCard/components/blocks';
import { FooterBlock, PreviewBlock, TitleBlock } from '../view/FlexibleCard/components/blocks';
import * as Elements from '../view/FlexibleCard/components/elements';
export var isFlexibleUiCard = function isFlexibleUiCard(children, ui) {
  if (ui !== null && ui !== void 0 && ui.removeBlockRestriction) {
    var _React$Children$toArr;
    return children && ((_React$Children$toArr = React.Children.toArray(children)) === null || _React$Children$toArr === void 0 ? void 0 : _React$Children$toArr.length) > 0 ? true : false;
  }
  if (children && React.Children.toArray(children).some(function (child) {
    return _isFlexibleUiTitleBlock(child);
  })) {
    return true;
  }
  return false;
};
export var 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 = function isFlexibleUiBlock(node) {
  if (! /*#__PURE__*/React.isValidElement(node)) {
    return false;
  }
  if (isStyleCacheProvider(node)) {
    // Component wrapped with compiled at runtime, check for children
    var isChildrenValid = true;
    React.Children.map(node.props.children, function (child) {
      var _child$type;
      if (! /*#__PURE__*/React.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;
};
export { _isFlexibleUiBlock as isFlexibleUiBlock };
var _isFlexibleUiElement = function isFlexibleUiElement(node) {
  if (! /*#__PURE__*/React.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.Children.map(node.props.children, function (child) {
      var _child$type2;
      if (! /*#__PURE__*/React.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;
};
export { _isFlexibleUiElement as isFlexibleUiElement };
var _isFlexibleUiTitleBlock = function isFlexibleUiTitleBlock(node) {
  if (! /*#__PURE__*/React.isValidElement(node)) {
    return false;
  }
  if (node.type === TitleBlock) {
    return true;
  }
  if (isStyleCacheProvider(node)) {
    // Component wrapped with compiled at runtime, check for children
    var isChildrenValid = true;
    React.Children.map(node.props.children, function (child) {
      var _child$type3;
      if (! /*#__PURE__*/React.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;
};
export { _isFlexibleUiTitleBlock as isFlexibleUiTitleBlock };
var _isFlexibleUiPreviewBlock = function isFlexibleUiPreviewBlock(node) {
  if (! /*#__PURE__*/React.isValidElement(node)) {
    return false;
  }
  if (node.type === PreviewBlock) {
    return true;
  }
  if (isStyleCacheProvider(node)) {
    // Component wrapped with compiled at runtime, check for children
    var isChildrenValid = true;
    React.Children.map(node.props.children, function (child) {
      var _child$type4;
      if (! /*#__PURE__*/React.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;
};
export { _isFlexibleUiPreviewBlock as isFlexibleUiPreviewBlock };
export var isFlexibleUiFooterBlock = function isFlexibleUiFooterBlock(node) {
  return /*#__PURE__*/React.isValidElement(node) && node.type === FooterBlock;
};