var settings = [{
    Language1: "CONFIGURACIÓN GENERAL",
    Language2: "GENERAL SETTINGS",
    Settings: [
        {
            Language1: "Lenguaje",
            Language2: "Language",
            Type: "Select2",
            ID: "LanguageSelect",
            Content: "",
            Function: "SetData.localStorage('ActiveLanguage',$('[name=\\'LanguageSelect\\']').select2('val'));location.reload();",
            Init: function() {
                
            }
        },
        {
            Language1: "Site",
            Language2: "Site",
            Type: "Select2",
            ID: "SiteSelect",
            Content: "",
            Function: "SetData.localStorage('Classification',$('[name=\\'SiteSelect\\']').select2('val'));location.href = 'app_select.html';",
            Init: function() {
                
            }
        },
        {
            Language1: "Temporada",
            Language2: "Season",
            Type: "Select2",
            ID: "FYSeason",
            Content: "",
            Function: "SetData.localStorage('Season',$('[name=\\'FYSeason\\']').select2('val'));location.reload();",
            Init: function() {
                
            }
        }
    ]
}];//, {
//        Language1: "CONFIGURACIÓN IMPRESORAS",
//        Language2: "PRINTERS SETTINGS",
//        Settings: [
//            {
//                Language1: "Impresora",
//                Language2: "Printer",
//                Type: "Select2",
//                ID: "PrinterSelect",
//                Content: "",
//                Function: ""
//            },
//            {
//                Language1: "Calibración",
//                Language2: "Calibration",
//                Type: "Button",
//                ID: "Calibration",
//                Content: "",
//                Function: ""
//            }
//        ]
//    }];

var topElement = '<div class="m-list-settings__item"><span class="m-list-settings__item-label">[TITLE]</span><span class="m-list-settings__item-control">';
var endElement = '</span></div>';

var select2Element = '<div class="m-select2 m-select2--air m-select2--pill">' +
    '                   <select class="form-control m-select2" name="[ID]" data-placeholder="Pill style" onchange="[FUNCTION]">' +
    '                       <option></option>' +
    '                   </select>' +
    '              </div>';

var switchElement = '<span class="m-switch m-switch--outline m-switch--icon-check m-switch--brand">' +
    '                   <label>' +
    '                       <input type="checkbox" name="[ID]" onchange="[FUNCTION]">' +
    '                           <span></span>' +
    '                   </label>' +
    '            </span>';

var buttonElement = '<button type="button" onclick="[FUNCTION]" name="[ID]" class="btn m-btn--pill btn-primary btn-block">Run</button>';

var settingsElements = "";

for (var m = 0; m < settings.length; m++) {
    
    settingsElements = '<div class="m-list-settings__group"><div class="m-list-settings__heading">' + Functions.LanguageSelect(settings[m].Language1, settings[m].Language2) + '</div>';
    for (var i = 0; i < settings[m].Settings.length; i++) {
        settingsElements += topElement.replace('[TITLE]', Functions.LanguageSelect(settings[m].Settings[i].Language1, settings[m].Settings[i].Language2));

        switch (settings[m].Settings[i].Type) {
            case "Select2":
                settingsElements += select2Element.replace("[ID]", settings[m].Settings[i].ID).replace("[CONTENT]", settings[m].Settings[i].Content).replace("[FUNCTION]", settings[m].Settings[i].Function);
                break;
            case "Switch":
                settingsElements += switchElement.replace("[ID]", settings[m].Settings[i].ID).replace("[CONTENT]", settings[m].Settings[i].Content).replace("[FUNCTION]", settings[m].Settings[i].Function);
                break;
            case "Button":
                settingsElements += buttonElement.replace("[ID]", settings[m].Settings[i].ID).replace("[FUNCTION]", settings[m].Settings[i].Function);
                break;
            default:
                break;
        }
        settingsElements += endElement;
    }
    settingsElements += '</div>';
}

$('.m-list-settings.m-scrollable').append(settingsElements);

function sidebarInit() {
    GetData.SingleSqlValue('Season', 'OS_App_Data', '1 = 1', true, true, function (ret) {
        var seasons = ret[0].Season.split(',');
        for (var i = 0; i < seasons.length; i++) {
            $('[name="FYSeason"]').append(new Option(seasons[i], seasons[i], (GetData.localStorage('Season') == seasons[i] ? true : false), (GetData.localStorage('Season') == seasons[i] ? true : false)));//.trigger('change');
        }
    });

    GetData.SingleSqlValue('Name', 'OS_Catalog', "Category = 38 and Name like '" + GetData.localStorage('Classification') + "|%'", true, true, function (ret) {
        $('[name="LanguageSelect"]').append(new Option(ret[0].Name.split('|')[1], 1, (GetData.localStorage('ActiveLanguage') == 1 ? true : false), (GetData.localStorage('ActiveLanguage') == 1 ? true : false)));//.trigger('change');
        $('[name="LanguageSelect"]').append(new Option(ret[0].Name.split('|')[2], 2, (GetData.localStorage('ActiveLanguage') == 2 ? true : false), (GetData.localStorage('ActiveLanguage') == 2 ? true : false)));//.trigger('change');
    });

    if (GetData.localStorage('AccessLevel') == '1') {
        GetData.SingleSqlValue('Name', 'OS_Catalog', "Category = 2 and CatActive = 1", true, true, function (ret) {
            for (var i = 0; i < ret.length; i++) {
                $('[name="SiteSelect"]').append(new Option(ret[i].Name, ret[i].Name, (GetData.localStorage('Classification') == ret[i].Name ? true : false), (GetData.localStorage('Classification') == ret[i].Name ? true : false)));//.trigger('change');
            }
        });
    } else {
        GetData.SingleSqlValue("Classification", "OS_User", "UserId = '" + GetData.localStorage('UserId') + "'", true, true, function (ret) {
            var RET = ret[0].Classification.split(',');
            for (var i = 0; i < RET.length; i++) {
                $('[name="SiteSelect"]').append(new Option(RET[i], RET[i], (GetData.localStorage('Classification') == RET[i] ? true : false), (GetData.localStorage('Classification') == RET[i] ? true : false)));//.trigger('change');
            }
        });
    }
}

sidebarInit();