<template>
  <v-snackbar
    v-model="modelValue"
    variant="flat"
  >
    <v-icon
      class="pr-3 shark-400"
      icon="error"
    />
    <span class="shark-950">{{ t('texts.measurementDeleted') }}</span>
    <template #actions>
      <v-btn
        class="ml-auto px-4 my-1"
        color="minsk_900"
        variant="flat"
        @click="undo"
      >
        <span>{{ t('labels.undo') }}</span>
      </v-btn>
    </template>
  </v-snackbar>
</template>

<script setup lang="ts">
import { useI18n } from 'vue-i18n';
import { DataOverlayType } from '@3cr/types-ts';
import { useViewer3cr } from '@/composables/useViewer3cr';
import { DataOverlay } from '@3cr/viewer-types-ts';

interface Props {
  measurement: DataOverlay;
}

const props = defineProps<Props>();

const { t } = useI18n();
const viewer3cr = useViewer3cr();

const modelValue = defineModel<boolean>({ default: false });

async function undo(): Promise<void> {
  const message = {
    Version: '0.0.0',
    Id: 'test',
    Data: JSON.stringify(props.measurement),
    DataType: DataOverlayType.Length, // TODO: determine based on measurement
  };

  await viewer3cr.createAnnotation({ message: [message] });
}
</script>
