import FpiForm from './src/form.vue';
import registRules from './utils/registRules.js';
import registComponent from './utils/registComponents.js';

/* istanbul ignore next */
FpiForm.install = function(Vue) {
  Vue.component(FpiForm.name, FpiForm);
};

// 校验规则注册
FpiForm.registValidateRules = function(name, rule) {
  registRules(name, rule);
};

// 批量校验规则注册
FpiForm.batchRegistValidateRules = function(rules) {
  if (!Array.isArray(rules)) rules = new Array(rules);
  for (const item of rules) registRules(item.name, item.rule);
};

// 组件注册
FpiForm.registComponents = function(name, component, defaultValue, defaultAttrs) {
  registComponent(name, component, defaultValue, defaultAttrs);
};

// 批量组件注册
FpiForm.batchRegistComponents = function(components) {
  if (!Array.isArray(components)) components = new Array(components);
  for (const item of components) {registComponent(item.name, item.component, item.defaultValue, item.defaultAttrs);}
};

export default FpiForm;
