﻿function SECTION_TRANSLATION(args){
    this.args = args;
    this.zoomer = args.zoomer;
    this.init_section_translation();
}

SECTION_TRANSLATION.prototype.args = null;
SECTION_TRANSLATION.prototype.zoomer = null;
SECTION_TRANSLATION.prototype.ready = false;

SECTION_TRANSLATION.prototype.translations = null;

SECTION_TRANSLATION.prototype.init_section_translation = function(){
    //create one-to-one match
    if(this.zoomer && this.zoomer.ready) {
        var all_translations = this.zoomer.get_section_translations();
        this.add_ga_tanslations(all_translations, this.zoomer.actual_sections, "GA");
        this.translations = all_translations;
        this.ready = true;
    } else {
        var _this = this;
        setTimeout(function() {_this.init_section_translation()}, 500);
    }
}

//SECTION_TRANSLATION.prototype.find_ga(section_list){
//    var ga_sections_list = [];
//    for(var i = 0; i < section_list.length; i++){
//        if(this.isGA(section_list[i]) || this.isLawn(section_list[i])){
//            ga_sections_list.push(section_list[i]);
//        }  
//    }
//    return ga_sections_list;
//}

SECTION_TRANSLATION.prototype.add_ga_tanslations = function(translations, section_list, ga_name){
    for(var i = 0; i < section_list.length; i++){
        if(this.isGA(section_list[i]) || this.isLawn(section_list[i])){
            translations[0].push(section_list[i]);
            translations[1].push(ga_name);
        }  
    }
}


SECTION_TRANSLATION.prototype.GA_DEF = ["GA", "G.A", "G.A.", "Gen Adm", "G/A", "GENERAL ADM", "GEN ADM", "GENADMN", "SRO", "General Admission"];
SECTION_TRANSLATION.prototype.GA_EXCLUDE_DEF = [ "GARDEN", "GARDEN BOX", "GATORS", "UGA" ];


SECTION_TRANSLATION.prototype.isGA = function(name){
    return array_indexOf(this.GA_DEF, name) != -1 && array_indexOf(this.GA_EXCLUDE_DEF, name) == -1
}

function array_indexOf(lst, name){
    for(var i = 0; i < lst.length; i++){
        if(name.toLowerCase().indexOf(lst[i].toLowerCase()) != -1) return i;
    }
    return -1;
}

SECTION_TRANSLATION.prototype.LAWN_DEF = ["LAWN", "GRASS"];
SECTION_TRANSLATION.prototype.isLawn = function(name){
    return array_indexOf(this.LAWN_DEF, name) != -1 
}

SECTION_TRANSLATION.prototype.trans_from_list_to_zoomer = function(name){
    var result = new Array();
    for(var i = 0; i < this.translations[0].length; i++){
        if(this.translations[0][i] == name) {
            result.push(this.translations[1][i]);
        }
    }
    if(result.length == 0) result.push(name);
    return result;
}

SECTION_TRANSLATION.prototype.trans_from_zoomer_to_list = function(name){
    var result = new Array();
    for(var i = 0; i < this.translations[0].length; i++){
        if(this.translations[1][i] == name) {
            result.push(this.translations[0][i]);
        }
    }
    if(result.length == 0) result.push(name);    
    return result;
}
