<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('Confirm deletion'),
                message: t('Are you sure you want to delete this roadmap?'),
                promise: remove,
            },
        })
        .onOk(async () => await router.push({ name: 'RouteRoadmap' }));
}

async function remove() {
    if (!props.route.id) {
        return;
    }
    await axios.delete(`Roadmaps/${props.route.id}`);
    quasar.notify({
        message: t('globals.dataDeleted'),
        type: 'positive',
    });
}
</script>
<template>
    <QItem @click="confirmRemove" v-ripple clickable>
        <QItemSection avatar>
            <QIcon name="delete" />
        </QItemSection>
        <QItemSection>{{ t('Delete roadmap') }}</QItemSection>
    </QItem>
</template>

<i18n>
es:
    Confirm deletion: Confirmar eliminación
    Are you sure you want to delete this roadmap?: ¿Estás seguro de que quieres eliminar esta troncal?
    Delete roadmap: Eliminar troncal
</i18n>
