export class ListviewAgHtmlCellRenderer {

    constructor() {
        this.renderOptionsDefaults = {};
        this.renderOptions = null;
        this.parent = null;
        this.gridApi = null;
        this.gui = null;
        this.value = null;
    }

    init(params) {
        this.gridApi = params.api;
        this.parent = params.context.parent;
        this.renderOptions = Object.assign(this.renderOptionsDefaults, (params.options) ? params.options : {});
        this.gui = document.createElement('div');
        this.gui.classList.add('ag-render-html-cell');
        this.value = document.createElement('span');
        this.value.classList.add('ag-render-html-cell-value');
        if (params.value !== undefined) this.value.innerHTML = params.valueFormatted ? params.valueFormatted : params.value;
        else this.value.innerHTML = '';
        this.gui.appendChild(this.value);
    }

    getGui() {
        return this.gui;
    };

    destroy() {
        this.renderOptionsDefaults = null;
        this.renderOptions = null;
        this.parent = null;
        this.gridApi = null;
        this.gui = null;
        this.value = null;
    }

    refresh(params) {
        this.value.innerHTML = params.valueFormatted ? params.valueFormatted : params.value;
        return true;
    }
}

export class ListviewAgHtmlLoadingCellRenderer {

    constructor() {
        this.renderOptionsDefaults = {
            spinner: '<img src="res/components/user/sig-control-listview-ag/spinner.gif" />'
        };
        this.renderOptions = null;
        this.parent = null;
        this.gridApi = null;
        this.gui = null;
        this.value = null;
        this.spinner = null
    }

    init(params) {
        this.gridApi = params.api;
        this.parent = params.context.parent;
        this.renderOptions = Object.assign(this.renderOptionsDefaults, (params.options) ? params.options : {});
        this.spinner = this.renderOptions.spinner;
        this.gui = document.createElement('div');
        this.gui.classList.add('ag-render-loading-cell');
        this.value = document.createElement('span');
        this.value.classList.add('ag-render-loading-cell-value');
        if (params.value !== undefined) this.value.innerHTML = params.valueFormatted ? params.valueFormatted : params.value;
        else this.value.innerHTML = this.spinner;
        this.gui.appendChild(this.value);
    }

    getGui() {
        return this.gui;
    };

    destroy() {
        this.renderOptionsDefaults = null;
        this.renderOptions = null;
        this.parent = null;
        this.gridApi = null;
        this.gui = null;
        this.value = null;
        this.spinner = null
    }

    refresh(params) {
        if (params.value) this.value.innerHTML = params.valueFormatted ? params.valueFormatted : params.value;
        else this.value.innerHTML = this.spinner;
        return true;
    }
}