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

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

        computed: {
            myitems() {
                
                if(this.app.platform == 'b2b')
                {
                    
                    let rows = [];
                    _.each(this.items, row => {

                        let newrow = {};

                        let fields = _.keys(row);

                        _.each(fields, field => {

                            if(row[field].column.type != 'STATUS')
                            {
                                newrow[field] = row[field];
                            } 
                        })

                        rows.push(newrow);
                    })
                    return rows;
                }
                else
                {
                    return this.items;
                }

                
            },

            Customerregistru() {
                return this.app.classes.Customerregistru;
            },
        },
        
        methods: {
            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),
                });
            },

            Componentname(column) {
                return 'registru-table-body-column-' + _.capitalize(column.column.type);
            }
        },
        name: 'CustomerRegisterTableBody',
    }
</script>