<template>
    <v-card tile flat class="overflow-y-auto" :height="height" :disabled="disabled">

        <v-card-text class="pa-2">
            <v-alert type="info" dense v-if="items.length == 0" outlined>
            
                <span class="text-caption">
                    {{ __('Nu sunt registre.') }}
                </span>

            </v-alert>

            <template v-else>
                <customer-registers-list-item 
                    v-for="(item, index) in myitems"
                    :key="'item-' + index"
                    :app="app"
                    :item="item"
                    class="mb-2"
                />
            </template>

        </v-card-text>
        
    </v-card>
</template>

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

        computed: {
            myitems() {
                let r = _.orderBy(this.items, [item => item.date, item => 1 * item.number], ['desc', 'desc']);
                if(this.app.platform == 'b2b')
                {
                    r = _.filter(r, item => item.status == 'public');
                }
                return r;
            }
        },

        created() {
            let i = setInterval( () => {
                if( this.app.dataSession.Registrelemele.processing === false)
                {
                    clearInterval(i);
                    if(this.myitems.length > 0)
                    {
                        this.app.classes.Customerregistru.activeRegistru = this.myitems[0];
                    }
                }
            }, 350)
        },

        name: 'CustomerRegistersList',
    }
</script>