import { computed } from "vue";

export function useVModel(props, propsName, emit) {
  return computed({
    get() {
      return new Proxy(props[propsName], {
        get(target, key, receiver) {
          return Reflect.get(target, key, receiver);
        },
        set(target, key, val) {
          emit(`update:${propsName}`, { ...target, [key]: val });
          return true;
        },
      });
    },
    set(val) {
      emit(`update:${propsName}`, val);
    },
  })

}