<script setup>
import BasicTable from '@/Components/BasicTable.vue';
import { LinkOptions as C_LINK, TableColumn as C_TD, TableRow as C_TR} from '@/Shared/AppObjects';


const props = defineProps({
    client_case: Object,
    activities: Object
});


let header = [
    C_TD.make('Pogodba', 'header'),
    C_TD.make('Datum', 'header'),
    C_TD.make('Akcija', 'header'),
    C_TD.make('Odločitev', 'header'),
    C_TD.make('Opomba', 'header'),
    C_TD.make('Datum zapadlosti', 'header'),
    C_TD.make('Znesek obljube', 'header'),
    C_TD.make('Dodal', 'header')
];

const createBody = (data) => {
    let body = [];

    data.forEach((p) => {
        const createdDate =  new Date(p.created_at).toLocaleDateString('de');
        const dueDate = (p.due_date) ? new Date().toLocaleDateString('de') : null;
        const userName = (p.user && p.user.name) ? p.user.name : (p.user_name || '');

        const cols = [
            C_TD.make(p.contract?.reference ?? ''),
            C_TD.make(createdDate, 'body' ),
            C_TD.make(p.action.name, 'body'),
            C_TD.make(p.decision.name, 'body'),
            C_TD.make(p.note, 'body' ),
            C_TD.make(dueDate, 'body' ),
            C_TD.make(Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(p.amount), 'body' ),
            C_TD.make(userName, 'body')
        ];

        body.push(
            C_TR.make(cols)
        )
    });

    return body;
}

</script>
<template>
    <BasicTable :header="header" :body="createBody(activities.data)" />
</template>