﻿//TOAST
//Show toast Parameters explaination
//Title: You title
//Message: You message
//Type: success|info|error|warning
//Position: toast-top-right/left | toast-bottom-right/left | toast-top/bottom-full-width 
//Show/Hide Easing: swing|linear
//Show/Hide Method: show/hide|fadeIn/fadeOut|slideUp/slideDown
//Timing by "ms"
//
//Example:
//args = {
//    "closeButton": "true|false",
//    "debug": "true|false",
//    "newestOnTop": "true|false",
//    "progressBar": "true|false",
//    "positionClass": "toast-top-right/left | toast-bottom-right/left | toast-top/bottom-full-width ",
//    "preventDuplicates": "true|false",
//    "showDuration": 300,
//    "hideDuration": 1000,
//    "timeOut": 5000
//    "extendedTimeOut": (args.extenedTimeOut !== undefined && args.extenedTimeOut !== null) ? args.extenedTimeOut.toString() : "1000",
//    "showEasing": "swing",
//    "hideEasing": "linear",
//    "showMethod": "fadeIn",
//    "hideMethod": "fadeOut"
//}

var MessageUtil = new function MessageUtil() {
    var self = this;
    self.ShowMessage = function (args) {
        toastr.options = {
            "closeButton": args.closeButton ?? true,
            "debug": args.debug ?? false,
            "newestOnTop": args.newestOnTop ?? true,
            "progressBar": args.progessBar ?? false,
            "positionClass": args.position ?? "toast-top-right",
            "preventDuplicates": args.preventDuplicates ?? true,
            "showDuration": args.showDuration ?? 300,
            "hideDuration": args.hideDuration ?? 1000,
            "timeOut": (args.timeOut !== undefined && args.timeOut !== null) ? args.timeOut.toString() : "5000",
            "extendedTimeOut": (args.extenedTimeOut !== undefined && args.extenedTimeOut !== null) ? args.extenedTimeOut.toString() : "1000",
            "showEasing": args.showEasing ?? "swing",
            "hideEasing": args.hideEasing ?? "linear",
            "showMethod": args.showMethod ?? "fadeIn",
            "hideMethod": args.hideMethod ?? "fadeOut"
        }
        args.type = args.type ?? "success";
        args.message = args.message ?? "";
        args.title = args.title ?? "";
        switch (args.type) {
            case ("success"): {
                toastr.success(args.message, args.title);
            } break;
            case ("info"): {
                toastr.info(args.message, args.title);
            } break;
            case ("error"): {
                toastr.error(args.message, args.title);
            } break;
            case ("warning"): {
                toastr.warning(args.message, args.title);
            } break;
            default: {
                toastr.info(args.message, args.title);
            } break;
        }
    }
}