/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var VueCompositionAPI = require('@vue/composition-api');
var kebabCase = require('lodash/kebabCase');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var kebabCase__default = /*#__PURE__*/_interopDefaultLegacy(kebabCase);

function useVModel(value, defaultValue, onChange) {
  let eventName = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "change";
  let propName = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : "value";
  let alias = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : [];
  const {
    emit,
    vnode
  } = VueCompositionAPI.getCurrentInstance();
  const internalValue = VueCompositionAPI.ref();
  internalValue.value = defaultValue;
  const isControlled = Object.prototype.hasOwnProperty.call(vnode.componentOptions.propsData, propName) || Object.prototype.hasOwnProperty.call(vnode.componentOptions.propsData, kebabCase__default["default"](propName));
  if (isControlled) {
    return [value, function (newValue) {
      for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
        args[_key - 1] = arguments[_key];
      }
      emit === null || emit === void 0 ? void 0 : emit("input", newValue, ...args);
      onChange === null || onChange === void 0 ? void 0 : onChange(newValue, ...args);
      if (eventName && eventName !== "input") emit === null || emit === void 0 ? void 0 : emit(eventName, newValue, ...args);
    }];
  }
  for (let i = 0, len = alias.length; i < len; i++) {
    const item = alias[i];
    if (Object.prototype.hasOwnProperty.call(vnode.componentOptions.propsData, item.propName)) {
      return [item.value, function (newValue) {
        for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
          args[_key2 - 1] = arguments[_key2];
        }
        emit === null || emit === void 0 ? void 0 : emit(`update:${item.propName}`, newValue, ...args);
        onChange === null || onChange === void 0 ? void 0 : onChange(newValue, ...args);
        if (item.eventName && item.eventName !== "input") emit === null || emit === void 0 ? void 0 : emit(item.eventName, newValue, ...args);
      }];
    }
  }
  return [internalValue, function (newValue) {
    internalValue.value = newValue;
    for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
      args[_key3 - 1] = arguments[_key3];
    }
    onChange === null || onChange === void 0 ? void 0 : onChange(newValue, ...args);
    if (eventName && eventName !== "input") emit === null || emit === void 0 ? void 0 : emit(eventName, newValue, ...args);
  }];
}

exports["default"] = useVModel;
//# sourceMappingURL=use-vmodel.js.map
