import { type ModelRef, ref, type Ref, unref, watch } from 'vue'; type FlyoutLike = { close(): void; }; type UseDateFlyoutOptions = { compareKey?(value: T | null): string | number | null | undefined; transformIn?(value: T | null): T | null; }; export default function ( modelValue: ModelRef, flyoutRef: Readonly>, options: UseDateFlyoutOptions = {} ): Ref { const localValue = ref(null) as Ref; let isExternalUpdate = false; watch(localValue, value => { if (isExternalUpdate) { isExternalUpdate = false; return; } unref(flyoutRef)?.close(); if (options.compareKey && options.compareKey(modelValue.value) === options.compareKey(value)) { return; } modelValue.value = value; }); watch(modelValue, value => { const next = options.transformIn ? options.transformIn(value) : value; if (Object.is(next, unref(localValue))) { return; } isExternalUpdate = true; localValue.value = next; }, {immediate: true}); return localValue; }