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, value, receiver) {
          emit(`update:${propsName}`, { ...target, [key]: value });
          return true;
        },
      });
    },
    set: (val) => {
      emit(`update:${propsName}`, val);
    },
  });

}