window.ShowToastr = (type, message, title) => {
    toastr.options.positionClass = 'toast-bottom-left';

    let finalTitle = title && title.trim() !== "" ? title : (type === "success" ? "Операция выполнена" : type == "error" ? "Ошибка операции" : "Уведомление");

    if (type === "success") {
        toastr.success(message, finalTitle, { timeOut: 5000 });
    }

    if (type === "error") {
        toastr.error(message, finalTitle, { timeOut: 5000 });
    }

    if (type === "info") {
        toastr.info(message, finalTitle, { timeOut: 5000 });
    }
}

window.getTableHtml = () => {
    const table = document.querySelector("#journalTable");
    return table ? table.outerHTML : "failed";
};

window.ShowSweetAlert = (type, message) => {

    typeTitle = "";
    typeIcon = "";

    if (type == "success") {
        typeTitle = "Success";
        typeIcon = "success";
    }

    if (type == "error") {
        typeTitle = "Error";
        typeIcon = "error";
    }

    Swal.fire({
        title: typeTitle,
        text: message,
        icon: typeIcon,
        confirmButtonText: "Ok"
    })
}

function focusInput(element) {
    if (element instanceof HTMLElement) {
        element.focus();
    }
}

function ShowPasswordBoxModal() {
    $('#passwordBoxModal').modal('show');
    $('#passInput').trigger('focus');
}

function HidePasswordBoxModal() {
    $('#passwordBoxModal').modal('hide');
}

function ShowLogDataTableModal() {
    $('#logDataTableModal').modal('show');
}

function ShowConfirmationBoxModal() {
    $('#confirmationBoxModal').modal('show');
}

function HideConfirmationBoxModal() {
    $('#confirmationBoxModal').modal('hide');
}
