<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({
    shelving: {
        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 shelving?'),
                promise: remove
            },
        })
}

async function remove() {
    if (!$props.shelving.id) {
        return;
    }
    await axios.delete(`Shelvings/${$props.shelving.id}`);
    await router.push({ name: 'ShelvingList' });
    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 Shelving') }}</QItemSection>
    </QItem>
</template>

<i18n>
es:
    Confirm deletion: Confirmar eliminación
    Are you sure you want to delete this shelving?: ¿Seguro que quieres eliminar este carro?
    Delete Shelving: Eliminar carro
</i18n>
