<template>
    <div class="Domainlist">
        <h1>Domainlist</h1>
        <scroll-table :actions="actions" :columns="columns" :new-rows="newRows" :has-more="hasMore" :loading="loading" :handler="more" orderBy="Name" :orderDesc="false" :limit="50"></scroll-table>
    </div>
</template>

<script>
import ScrollTable from 'components/scroll-table.vue';

export default {
    name: "Domainlist",
    components: {
        ScrollTable
    },
    data() {
        return {
            actions: [{
                title: 'Edit',
                icon: 'icon-pencil',
                action(row) {
                    console.log("yay edit", row);
                }
            }, {
                title: 'Duplicate',
                icon: 'icon-docs',
                action(row) {
                    console.log("yay duplicate", row);
                }
            }, {
                title: 'Hide',
                icon: 'icon-eye-off',
                action(row) {
                    console.log("yay hide", row);
                }
            }],
            columns: [{
                heading: 'ID',
                prop: 'ID',
                orderBy: 'id',
                align: 'right',
                colStyle: {
                    width: '70px'
                },
                cellStyle: {
                    color: '#999'
                }
            }, {
                heading: 'TLD',
                prop: 'TLD',
                orderBy: 'tld',
                align: 'left'
            }, {
                heading: 'Domain',
                prop: 'Name',
                orderBy: 'name'
            }],
            newRows: [ ],
            hasMore: true,
            loading: false
        }
    },
    methods: {
        more(offset, limit, orderBy, orderDesc, search) {
            this.loading = true;
            this.$store.dispatch('apiRequest', {
                endpoint: 'domains',
                params: {
                    start: offset,
                    length: limit,
                    orderBy,
                    orderDesc,
                    search
                }
            })
                .then(rows => {
                    this.hasMore = (rows.length >= limit);
                    this.newRows = rows;
                    this.loading = false;
                })
                .catch(error => {
                    this.loading = false;
                    this.hasMore = false;

                    console.log(error);
                });

        }
    }
}
</script>
