/**
 * Base.Autocomplete 1.0
 *
 * Requiere
 *     Base 1.0
 *     https://sweetalert2.github.io/#configuration
 */
$(function() {

    $.extend(Base, {
        Alert : {

            simple: function(message, text, type){

                 //Type: warning error success info question
                 Swal.fire(message, text, type);
            },

            custom: function (options) {

                 //Option Convert/Compatibility
                 var convertOptions = {};
                 if(options != undefined){
                     if(options.type != undefined){
                         convertOptions.icon = options.type;
                         delete options['type'];
                     }
                 }

                 var defaultOptions = {
                    title: "",
                    text: "",
                    icon: "success", //warning error success info question

                    buttonsStyling: true,
                    showCloseButton: false,
                    reverseButtons: false,
                    customClass: {
                    },

                    backdrop: false,
                    toast: false,
                    allowEscapeKey: false,
                    allowEnterKey: false,

                    showConfirmButton: true,
                    confirmButtonText: "Aceptar",
                    focusConfirm: false,

                    showDenyButton: false,
                    denyButtonText: "Denegar",
                    focusDeny: false,

                    showCancelButton: false,
                    cancelButtonText: "Cancelar",
                    focusCancel: false,

                    callBackThen: null
                };
                switch (defaultOptions.type) {
                    case "warning": {
                        defaultOptions.title = gedux.i18n.gral.title.warning
                    }break;
                    case "error": {
                        defaultOptions.title = gedux.i18n.gral.title.error
                    }break;
                    case "success": {
                        defaultOptions.title = gedux.i18n.gral.title.success
                    }break;
                    case "info": {
                        defaultOptions.title = gedux.i18n.gral.title.info
                    }break;
                    case "question": {
                        defaultOptions.title = gedux.i18n.gral.title.question
                    }break;
                }

                var finallyOptions = $.extend(true, defaultOptions, options, convertOptions);


                Swal.fire(finallyOptions)
                    .then(function(result){

                        if(finallyOptions.callBackThen != undefined && finallyOptions.callBackThen != null && $.isFunction(finallyOptions.callBackThen)) {

                            return finallyOptions.callBackThen(result);
                        }
                 });
            },

            _qxAlert : function (swalert) {

                return {

                    ver : function () {

                        console.log("Base.Alert 1.0");
                        console.log("Requiere: Base 1.0");
                    }
                }
            }
        }
    });

    $.fn.QxAlert = function () {

        var swalert = this;

        return Base.Alert._qxAlert(swalert);
    }
});