<template>
  <v-dialog
    v-model="modal"
    width="535"
  >
    <v-card>
      <v-card-title class="px-6 py-2 text-h3">
        <span>{{ t('labels.measurementDelete') }}</span>
      </v-card-title>
      <v-card-text
        class="px-6 pt-0 pb-4"
        style="font-size: 14px; line-height: 20px; font-weight: 400"
      >
        <span>{{ t('texts.measurementDeleteConfirm') }}</span>
      </v-card-text>
      <v-card-actions class="px-6 pt-0 pb-4">
        <v-spacer />
        <v-btn
          variant="plain"
          @click="modal = false"
        >
          <span>{{ t('labels.cancel') }}</span>
        </v-btn>
        <v-btn
          color="amaranth_600"
          variant="flat"
          @click="deleteAnnotation"
        >
          <span>{{ t('labels.confirm') }}</span>
        </v-btn>
      </v-card-actions>
    </v-card>
  </v-dialog>
</template>

<script setup lang="ts">
import { useViewer3cr } from '@/composables/useViewer3cr';
import { storeToRefs } from 'pinia';
import { useI18n } from 'vue-i18n';
import { useViewerStore } from '@/stores/viewer.store';
import { DataOverlayMeasurement } from '@3cr/viewer-types-ts';

interface Props {
  measurement: DataOverlayMeasurement;
}

const props = defineProps<Props>();

const viewer3cr = useViewer3cr();
const { t } = useI18n();
const { s_measurementDelete, measurementToDelete } =
  storeToRefs(useViewerStore());

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

async function deleteAnnotation(): Promise<void> {
  const message = { Version: '0.0.0', Id: props.measurement!.Id };
  await viewer3cr.removeAnnotation({ message });
  s_measurementDelete.value = true;
  measurementToDelete.value = props.measurement;
  modal.value = false;
}
</script>
