<script setup>
import axios from 'axios';
import { useQuasar } from 'quasar';
import { useI18n } from 'vue-i18n';
import { useRouter } from 'vue-router';
import VnConfirm from 'components/ui/VnConfirm.vue';

const props = defineProps({
    route: {
        type: Object,
        required: true,
    },
});

const router = useRouter();
const quasar = useQuasar();
const { t } = useI18n();

function confirmRemove() {
    quasar
        .dialog({
            component: VnConfirm,
            componentProps: {
                title: t('confirmDeletion'),
                message: t('confirmDeletionMessage'),
                promise: remove,
            },
        })
        .onOk(async () => await router.push({ name: 'RouteList' }));
}

async function remove() {
    if (!props.route.id) {
        return;
    }
    await axios.delete(`Routes/${props.route.id}`);
    quasar.notify({
        message: t('globals.dataDeleted'),
        type: 'positive',
    });
}

//  TODO: Add reports
</script>
<template>
    <QItem @click="confirmRemove" v-ripple clickable>
        <QItemSection avatar>
            <QIcon name="delete" />
        </QItemSection>
        <QItemSection>{{ t('deleteRoute') }}</QItemSection>
    </QItem>
</template>

<i18n>
en:
    confirmDeletion: Confirm deletion
    confirmDeletionMessage: Are you sure you want to delete this route?
    deleteRoute: Delete route
es:
    confirmDeletion: Confirmar eliminación,
    confirmDeletionMessage: Seguro que quieres eliminar esta ruta?
    deleteRoute: Eliminar ruta
</i18n>
