import { type Ref, defineComponent, inject, ref } from 'vue'; import { useI18n } from 'vue-i18n'; import { useRoute, useRouter } from 'vue-router'; import { useAlertService } from '@/shared/alert/alert.service'; import { type IChoice } from '@/shared/model/choice.model'; import ChoiceService from './choice.service'; export default defineComponent({ name: 'ChoiceDetails', setup() { const choiceService = inject('choiceService', () => new ChoiceService()); const alertService = inject('alertService', () => useAlertService(), true); const route = useRoute(); const router = useRouter(); const previousState = () => router.go(-1); const choice: Ref = ref({}); const retrieveChoice = async choiceId => { try { const res = await choiceService().find(choiceId); choice.value = res; } catch (error) { alertService.showHttpError(error.response); } }; if (route.params?.choiceId) { retrieveChoice(route.params.choiceId); } return { choice, previousState, t$: useI18n().t, }; }, });