import { computed as e, reactive as t, ref as n } from "vue";
/**
* Creates a reactive local model with optional transformation and validation logic.
*
* @template T The type of the model's value.
*
* @param model - A `Ref` representing the underlying value.
* @param options - Optional configuration for validation and parsing.
* @param options.update - A function that takes the transformed value and returns `true` if it should be applied to the model, or `false` to keep it in a cached state.
* @param options.parse - A function that takes the input value and returns a transformed value of type `T`. If omitted, the value is used as-is.
*
* @returns A reactive object with the following properties:
* - `value`: A computed property for getting and setting the model value.
* - `error`: A `Ref<string | undefined>` containing the last error message, if any.
* - `reset`: A method to clear the cached value and error state.
*
* ### Example
* ```ts
* import { ref } from 'vue';
* import { useTransformedModel } from './useTransformedModel';
*
* const model = ref<number>(42);
*
* const transformedModel = useTransformedModel(model, {
*   parse: (value) => {
*     const parsed = Number(value);
*     if (!Number.isFinite(parsed)) throw new Error('Invalid number');
*     return parsed;
*   },
*   update: (value) => value >= 0, // Only allow non-negative numbers
* });
*/
function r(r, i) {
	let a = n(), o = n(), { parse: s, update: c } = i, l = () => {
		a.value = void 0, o.value = void 0;
	};
	return t({
		value: e({
			get() {
				return a.value === void 0 ? r.value : a.value;
			},
			set(e) {
				l();
				try {
					let t = s ? s(e) : e;
					!c || c(t) ? r.value = t : a.value = t;
				} catch (t) {
					a.value = e, o.value = t instanceof Error ? t.message : String(t);
				}
			}
		}),
		error: o,
		reset: l
	});
}
export { r as useTransformedModel };

//# sourceMappingURL=useTransformedModel.js.map