import { extend } from '../vue';
import { EVENT_NAME_INPUT } from '../constants/events';
import { PROP_TYPE_ANY } from '../constants/props';
import { makeProp } from './props';

const makeModelMixin = function (prop) {
  let {
    type = PROP_TYPE_ANY,
    defaultValue = undefined,
    validator = undefined,
    event = EVENT_NAME_INPUT
  } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  const props = {
    [prop]: makeProp(type, defaultValue, validator)
  };

  // @vue/component
  const mixin = extend({
    model: {
      prop,
      event
    },
    props
  });
  return {
    mixin,
    props,
    prop,
    event
  };
};

export { makeModelMixin };
