<template>
  <Action :text="text" icon="home" :variant="variant" @click="reset" />
</template>

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

interface Props {
  view: ScanView;
  variant?: 'button' | 'menu-item';
}

withDefaults(defineProps<Props>(), {
  variant: 'button'
});

const { t } = useI18n();
const viewer3cr = useViewer3cr();
const { defaultLayout2x2 } = storeToRefs(useViewerStore());

const text = computed(() => {
  return t('labels.resetView');
});

async function reset(): Promise<void> {
  await viewer3cr.viewSelection(ViewSelectionActions.vs06);
  await viewer3cr.viewSelection(ViewSelectionActions.vs05);
  const message = { Version: '0.0.0', PositionData: defaultLayout2x2.value };
  await viewer3cr.customLayout({ message });
}
</script>
