<script setup>
import { watch } from "vue";
import { cloneDeep } from "lodash-es";
const props = defineProps({
  itemValue: { type: null, required: false },
  hook: { type: Function, required: false },
  modelValue: { type: null, required: false }
});
const emit = defineEmits(["update:modelValue"]);
watch(() => props.itemValue, (newValue, oldValue) => {
  const resultValue = cloneDeep(newValue);
  if (props.hook) {
    Promise.resolve(props.hook(resultValue, props.modelValue, newValue, oldValue)).then((result) => {
      emit("update:modelValue", result);
    }).catch((e) => void e);
  } else {
    emit("update:modelValue", resultValue);
  }
}, { deep: true, immediate: true });
</script>

<template>
  <input
    type="hidden"
    v-bind="$attrs"
  >
</template>
