import { isUsable, isStr, isPlainObj } from '@teamix/utils';
// 获取Schema是否包含默认值、异步默认值、必选校验等
var useSpecialProps = function useSpecialProps(props) {
  var initialValues = props.initialValues,
    initialRequest = props.initialRequest;
  var hasChangeDefault = !!initialValues || !!initialRequest; // 会触发onChange的默认值
  var hasDefault = hasChangeDefault;
  var hasRequired = false;
  var hasDefaultOrRule = function hasDefaultOrRule(schema) {
    schema.forEach(function (item) {
      var value = item.default,
        required = item.required,
        rules = item.rules,
        dataSource = item.dataSource,
        children = item.children;
      // 字符串变量配置default值会触发onChange
      hasChangeDefault = hasChangeDefault || !!(isPlainObj(dataSource) && isStr(value) && value.indexOf('.dataSource'));
      hasDefault = hasDefault || isUsable(value);
      hasRequired = hasRequired || required || !!rules;
      if (children === null || children === void 0 ? void 0 : children.length) {
        hasDefaultOrRule(children);
      }
    });
  };
  hasDefaultOrRule(props.schema);
  return {
    hasDefault: hasDefault,
    hasChangeDefault: hasChangeDefault,
    hasRequired: hasRequired
  };
};
export default useSpecialProps;