"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.transformCommonProps = exports.transformColorStyle = exports.replaceNode = void 0;
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _lowcodeEngine = require("@alilc/lowcode-engine");
var replaceNode = exports.replaceNode = /*#__PURE__*/function () {
  var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(type) {
    var nodeSchema;
    return _regenerator["default"].wrap(function _callee$(_context) {
      while (1) switch (_context.prev = _context.next) {
        case 0:
          nodeSchema = _lowcodeEngine.project.getCurrentDocument().selection.node.schema;
          nodeSchema.componentName = type;
          _lowcodeEngine.project.getCurrentDocument().selection.node.replaceWith(nodeSchema);
        case 3:
        case "end":
          return _context.stop();
      }
    }, _callee);
  }));
  return function replaceNode(_x) {
    return _ref.apply(this, arguments);
  };
}();
var transformCommonProps = exports.transformCommonProps = function transformCommonProps(props) {
  var commonProps = {};
  if (props.aspectRatio && props.aspectRatio.length > 0) {
    commonProps["aspect-ratio"] = props.aspectRatio;
  }
  if (props.flexGrow && props.flexGrow.length > 0) {
    commonProps["flex-grow"] = props.flexGrow;
  }
  if (props.flexShrink && props.flexShrink.length > 0) {
    commonProps["flex-shrink"] = props.flexShrink;
  }
  if (props.minWidth && props.minWidth.length > 0) {
    commonProps["min-width"] = props.minWidth;
  }
  if (props.minHeight && props.minHeight.length > 0) {
    commonProps["min-height"] = props.minHeight;
  }
  if (props.maxWidth && props.maxWidth.length > 0) {
    commonProps["max-width"] = props.maxWidth;
  }
  if (props.maxHeight && props.maxHeight.length > 0) {
    commonProps["max-height"] = props.maxHeight;
  }
  return commonProps;
};
var transformColorStyle = exports.transformColorStyle = function transformColorStyle(style) {
  var colorStyle = {};
  var colorProps = ["backgroundColor", "color", "tintColor", "placeholderColor", "border-color"];
  colorProps.forEach(function (prop) {
    if (style[prop] && typeof style[prop] === 'string') {
      var bgColor = transformThemeColor(style[prop]);
      if (bgColor.length > 0) {
        colorStyle[prop] = bgColor;
      }
    }
  });
  return colorStyle;
};
function transformThemeColor(color) {
  var regex = /theme\(0,\w+\)/g;
  if (color.match(regex) != null) {
    return "var(--" + color.replace("theme(0,", "").replace(")", "").trim() + ")";
  }
  return "";
}