<script setup>
import { useI18n } from 'vue-i18n';

import axios from 'axios';

const { t } = useI18n();

const $props = defineProps({
    transaction: {
        type: Object,
        required: true,
    },
    promise: {
        type: Function,
        required: true,
    },
});

const setClientsConfirmTransaction = async () => {
    try {
        const payload = { id: $props.transaction.id };
        await axios.post('Clients/confirmTransaction', payload);
        $props.promise();
    } catch (error) {
        return error;
    }
};
</script>

<template>
    <div v-if="!$props?.transaction?.isConfirmed">
        <QIcon
            @click.stop="setClientsConfirmTransaction"
            color="primary"
            name="done_all"
            size="sm"
            class="cursor-pointer"
        >
            <QTooltip>{{ t('Confirm transaction') }}</QTooltip>
        </QIcon>
    </div>
</template>

<i18n>
es:
    Confirm transaction: Confirmar transacción
</i18n>
