import _extends from "@babel/runtime/helpers/extends";
import React from 'react';
var normalizeNodeKey = function normalizeNodeKey(rawKey) {
  if (rawKey === undefined || rawKey === null) {
    return '';
  }
  return String(rawKey).replace(/^\.?\$?/, '');
};

/**
 * 从children数组中获取指定组件
 * @author ZhuGangMin
 * @date 2024-09-21 14:07:02
 * @param children 父组件传递过来children
 * @param key 组件的key
 * @param props 要覆盖的属性
 */
export function convertChildren(children, key, props) {
  var node;
  var targetKey = normalizeNodeKey(key);
  if (Array.isArray(children)) {
    for (var i = 0; i < children.length; i++) {
      var _child$props;
      var child = children[i];
      var childKey = normalizeNodeKey(child === null || child === void 0 ? void 0 : child.key);
      var childPropsKey = normalizeNodeKey(child === null || child === void 0 ? void 0 : (_child$props = child.props) === null || _child$props === void 0 ? void 0 : _child$props.key);
      if (childKey === targetKey || childPropsKey === targetKey) {
        // 属性融合
        var propsContact = props ? _extends({}, child.props, props) : child.props;
        node = /*#__PURE__*/React.cloneElement(child, propsContact);
        break;
      }
    }
  }
  return node;
}