<template>
    <span>
        <v-progress-circular
            indeterminate
            v-if="request.processing"
            size="20"
            width="1"
        >
        </v-progress-circular>

        <span
            v-else-if="customer"
        >
            {{ customer.name }}
        </span>
        
        <v-icon 
            v-else
            size="20"
            color="red"
        >
            mdi-alert
        </v-icon>
    </span>
</template>

<script>
    import Request from '@CsClasses/Request/Request';

    export default {
        props: {
            id: {required: true},
        },

        data: () => ({
            request: null,
            customer: null,
        }),

        created() {
            this.request = (new Request());
            this.request.processing = true;
            this.request
                .SetEndpoint('clienti/items')
                .SetData({
                    wheres: [
                        '(`customers`.`id` = ' + this.id + ')'
                    ],
                })
                .Request([
                    response => {
                        if(response.payload.paginator.data.length == 1)
                        {
                            this.customer = response.payload.paginator.data[0];
                        }
                    },
                ]);
        },

        name: 'CustomerById',
    }
</script>