(function ($, paw) {
    let coms = [];
    $.fn.xlsx = function (settings) {
        let $elt = $(this);
        let xlsx = new paw.com.XlsxComponent($elt, settings);
        coms.push({
            com: xlsx,
            $elt: $elt
        });
        xlsx.preview();
        return this;
    };

    $.fn.xlsxList = function (settings) {
        if (paw.utils.value.notSet(settings)) {
            settings = {};
        }
        settings.scaling = true;
        $(this).find('[data-xlsx-previewer]').each(function () {
            let $elt = $(this);
            var id = $elt.attr('id');
            var $data = $('[data-preview-id=' + id + ']');

            settings.url = $data.val();
            $elt.xlsx(settings);
        });
        return this;
    };

    $.fn.xlsxListRefresh = function () {
        var removeList = [];
        for (var i = 0; i < coms.length; i++) {
            if (coms[i].$elt.length === 0 || !coms[i].$elt.is(':visible')) {
                removeList.push(i);
                continue;
            }
            coms[i].com.compilePreview();
        }

        while (removeList.length > 0) {
            var index = removeList[0];
            coms.splice(index, 1);
            removeList.splice(0, 1);
        }
        return this;
    };
})(jQuery, paw);