<template>
    <tbody>
        <tr 
            v-for="(row, indexRow) in items" 
            :key="'row-' + indexRow"
            @contextmenu="OnRightClick($event, row)"
            :class="{
                'blue lighten-4': !fakeData && Customerregistru.activeRowId &&  (GetRowId(row) == Customerregistru.activeRowId),
            }"
        >
            <td
                v-for="(column, keyCol) in row"
                :key="'column-' + indexRow + keyCol"
            >
                <component
                    :is="Componentname(column)"
                    :column="column"
                    :app="app"
                    :fakeData="fakeData"
                >
                </component>
            </td>
        </tr>
    </tbody>
</template>

<script>
    export default {
        props: {
            app: {required: true},
            items: {default: () => []},
            fakeData: {default: false},
        },

        computed: {
            Customerregistru() {
                return this.app.classes.Customerregistru;
            },
        },
        
        methods: {
            Componentname(column) {
                return 'registru-table-body-column-' + _.capitalize(column.column.type);
            },

            GetRowId(row) {
                let row_id = null;
                _.each(row, item => {
                    row_id = item.row_id;
                })
                return row_id;
            },

            OnRightClick(e, row) {
                this.app.menus.Registrurowrightmenu.ShowRightMenu(e, {
                    ...row,
                    row_id: this.GetRowId(row),
                });
            }
        },
        name: 'RegistruTableBody',
    }
</script>