import { computed } from 'vue';

const saulVModel = (props, propName, emit) => {
  return computed({
    get() {
      if (typeof props[propName] === "object") {
        return new Proxy(props[propName], {
          set(obj, name, val) {
            emit(`update:${String(propName)}`, { ...obj, [name]: val });
            return true;
          }
        });
      }
      return props[propName];
    },
    set(val) {
      emit(`update:${String(propName)}`, val);
    }
  });
};

export { saulVModel };
