class Ctrl {
    static get $inject(){
        return ['$translate', '$http'];
    }
    constructor($translate, $http){
        this.lang = 'en-US';
        this.$translate = $translate;
        this.$http = $http;
        this.restParams = {};
        this.options = [];
        this.disabled = false;
        this.config = {
            closeOnSelect: false, 
            label: 'name', 
            id: 'id', 
            orderBy: 'name',
            similarityPerc: 10
        }
        console.log(this);
        this.api = {
            rest: {
                error: error => {
                    console.log(this);
                    console.log(error);
                },
                result: data => {
                }
            }
            
        }
        function pushrnd(arr){
            let rnd = Math.random().toString(36).substring(7);
            if (arr.some(o => o.name === rnd)) {
                pushrnd(arr);
            } else {
                arr.push({name: rnd});
            }
        }
        for (let i = 0; i < 15;i++){
            pushrnd(this.options);
        }
    }
    add(){
        function pushrnd(arr){
            let rnd = Math.random().toString(36).substring(7);
            if (arr.some(o => o.name === rnd)) {
                pushrnd(arr);
            } else {
                arr.push({name: rnd});
            }
        }
        pushrnd(this.options);
    }
    alter(){
        this.options[3].name = Math.random().toString(36).substring(7);
    }
    refresh($search){
        // if ($search) {
        //     this.restParams = {
        //         name: $search
        //     };
        // }
        
    }
    optionDisabled($item){
        return false;
    }
    remove($item){
    }
    select($item){
    }
    langa(){
        this.lang = this.lang === 'pt-BR' ? 'en-US' : 'pt-BR';
        this.$translate.use(this.lang);
    }
    disable(){
        this.disabled = !this.disabled;
    }
}

translate.$inject = ['$translateProvider'];
function translate($translateProvider){
    $translateProvider.translations('en-US', {
        noDataFound: 'No data found',
        placeholder: 'Insert here'
    });
    $translateProvider.translations('pt-BR', {
        noDataFound: 'Nada',
        placeholder: 'coloque aqui'
    });
    $translateProvider.preferredLanguage('en-US');
    $translateProvider.useSanitizeValueStrategy('sanitize');
}

angular.module('App', ['ngAnimate', 'ngSanitize', 'st.components', 'pascalprecht.translate', 'ui.bootstrap'])
.config(translate)    
.controller('Ctrl', Ctrl)
