define([
    'knockout',
    'arches',
    'js-cookie',
    'templates/views/components/plugins/resumen.htm'
], function(ko, arches, Cookies, ResumenTemplate) {

    const ResumenViewModel = function() {
        const self = this;
        this.loading = ko.observable(true);
        this.records = ko.observable();

        this.getStatus = async function() {
            const response = await window.fetch("../resumen/");
            const data = await response.json();
            self.bMueblesCount = data.b_muebles_count;
            self.bInmueblesCount = data.b_inmuebles_count;
            self.inmaterialCount = data.inmaterial_count;
            self.sitiosArqCount = data.sitios_arq_count;
            self.actoresCount = data.actores_count;
            self.digitalesCount = data.digitales_count;
            self.actividadesCount = data.actividades_count;
            self.records(data.records);
            self.loading(false);
        };

        this.saveStatus = async function() {
            const response = await fetch("../resumen/", {
                method: 'POST',
                credentials: 'include',
                headers: {
                    "X-CSRFToken": Cookies.get('csrftoken')
                }
            });
            const data = await response.json();
            self.records(data.records);
        };

        this.getStatus();
    };

    return ko.components.register('resumen', {
        viewModel: ResumenViewModel,
        template: ResumenTemplate
    });
});