<template>
  <t-date-picker
    v-model="valueData"
    value-type="time-stamp"
    :disabled="!config.writable"
    style="width: 100%"
    enable-time-picker
    format="YYYY/MM/DD HH:mm"
    :time-picker-props="{ format: 'HH:mm' }"
    @change="emitChange"
  />
</template>
<script setup name="DATE">
import { ref, watch } from 'vue';
const props = defineProps({
  config: { type: Object },
  modelValue: { type: Number },
});
const emit = defineEmits(['update:modelValue', 'change']);

const valueData = ref(null);

const emitChange = () => {
  emit('update:modelValue', valueData.value);
  emit('change', valueData.value);
};

watch(
  () => props.modelValue,
  (val, oldval) => {
    if (val === oldval) return;
    valueData.value = val || null;
  },
  {
    immediate: true,
  }
);
</script>
