const ICONID = 1;
const PATH = 2;
const STARTMONTH = 3;
const STARTDAY = 4;
const ENDMONTH = 5;
const ENDDAY = 6;
const CHECKSUM = 7

jOmnis.callbackObject = {
    index: null,
    logos: null,
    logoID: null,
    dataset: null,
    omnisOnLoad: function() {
        this.index = 0;
        this.logos = null;
        this.logoID = 0;
        this.dataset = false;
    },
    omnisSetData: function(logoSettings) {
        if(this.logos!=undefined){
            jOmnis.sendClickEvent(this.omnisGetCurrentLine());
            return
        }
        this.logos = [];
        logos = logoSettings.Logos.lstData
        if (logos.length>0) {
            this.dataset = true;
            for (var i = 0; i < logos.length; i++) {
                var logo = {
                    id:             logos[i][0],
                    path:           logos[i][1],
                    startMonth:     logos[i][2],
                    startDay:       logos[i][3],
                    endMonth:       logos[i][4],
                    endDay:         logos[i][5],
                    checksum:       logos[i][6],
                    omnisLine:      i+1};
                
                if(isLogoValid(logo)){
                    this.logos.push(logo);
                }
            }
        }
        this.recallLogo(logoSettings);
    },
    recallLogo: function(logoSettings){
        this.logoID = recallLogoHelper(logoSettings,this.logoID,this.logos);
        this.setLogo();
    },
    omnisGetCurrentLine: function(){
        var currentLogo = this.logos.find(x => x.id === this.logoID);
        if(currentLogo)
            return currentLogo.omnisLine;
        return 0;
    },
    setLogo: function(){
        if(this.logos.find(x => x.id === this.logoID) == undefined || !this.logos.find(x => x.id === this.logoID)["path"]){
            this.logoID = 19988;
        }
        jOmnis.sendClickEvent(this.omnisGetCurrentLine());
        document.getElementById("logo").src=this.logos.find(x => x.id === this.logoID)["path"];
    },
    incrementLogo: function(){
        for(var i = 0; i<this.logos.length-1; i++){
            if(this.logoID == this.logos[i].id){
                this.index = i;
                break;
            }
        }
        if(this.index == (this.logos.length-1)){
            this.logoID = this.logos[0].id
            this.index = 0;
        }
        else{
            this.index = this.index+1;
            this.logoID = this.logos[this.index].id;
        }
        jOmnis.sendClickEvent(this.omnisGetCurrentLine());
    }
};


window.addEventListener("click", function(e) {
    if(e.shiftKey){
        jOmnis.callbackObject.incrementLogo();
        jOmnis.callbackObject.setLogo();
    }
});