//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// TypeScript support for Blazor-WASM application | Author: Sergei Y.Kitaev
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Breakdown functions for unhandled error handling (static class):
class Breakdown {
    static SetUseDefaultErrorReporting() {
        Breakdown._UseDefaultErrorReporting_ = true;
    }
    static IgnoreErrorReportingWithDialog() {
        return Breakdown._UseDefaultErrorReporting_ || Breakdown._IsInErrorHandling_;
    }
    static HandlePageError(message, url, line, col, errorObj) {
        if (Breakdown.IgnoreErrorReportingWithDialog())
            return false; // do not filter default error output
        if (AFXUI.InvokeReturn('wasm_Breakdown_UseFatalBreakdownInstead'))
            return FatalBreakdown.HandlePageError(message, url, line, col, errorObj);
        Breakdown._IsInErrorHandling_ = true;
        let errorText = message ?
            'Error on web-page.' :
            'Undefined error on web-page.';
        if (url)
            errorText += '\nURL: ' + url;
        /*
              if (line)
                 errorText += '\nLine: '+line
        */
        let errorObjectAdded = false;
        if (errorObj) {
            try {
                errorText += '\n\n' + errorObj;
                errorObjectAdded = true;
            }
            catch (_a) { }
        }
        if (message && !errorObjectAdded)
            errorText += '\n\n' + message;
        Breakdown.ReportError(errorText);
        AFXUI.Invoke_1('wasm_Breakdown_NavigateToErrorPageFromScripError', errorText);
        return true; // filter default error output (allready printed in "ReportError")
    }
    static ShowWasmError(message, reloadCurrentPage) {
        if (!Breakdown.IgnoreErrorReportingWithDialog())
            Breakdown.ReportError(message, false, reloadCurrentPage);
    }
    static ReportError(message, traceError = true, reloadCurrentPage = false) {
        Breakdown._IsInErrorHandling_ = true;
        if (!message)
            message = 'Undefined error in SPA.';
        if (traceError)
            console.error(message);
        let tryReloadPage = reloadCurrentPage && !Breakdown._DamagedBehaviour_;
        let errorText = message;
        errorText += tryReloadPage ?
            '\n\nSPA-app.page will be reloaded.' :
            '\n\nYou will be directed to error description page.';
        if (reloadCurrentPage)
            errorText +=
                '\nIf app.page is found blocked, use "navigation-back" (or "navigation-forward") ' +
                    'browser-commands to switch to anothed page of this SPA.';
        errorText +=
            '\n(See error details in browser debug-console.)';
        alert(errorText);
        if (tryReloadPage)
            try {
                Magistral.InitiateReloadPage();
            }
            catch (e) {
                Breakdown._DamagedBehaviour_ = true;
                try {
                    FatalBreakdown.BlockSPA();
                }
                catch (x) {
                    console.error('Can not block WASM-functioning from JS:\n' + x.message);
                }
                errorText =
                    'Can not initiate app.page-reloading:' +
                        e.message;
                console.error(errorText);
                let reloadPage = page_loaded && App.IsReleaseConfiguration();
                let leavePageForDebug = !reloadPage;
                errorText += leavePageForDebug ?
                    '\nSee error details in browser debug console.' +
                        '\n(Further app.functioning is incorrect; reload the page maually.)'
                    : '\n\nWeb-application will be reloaded (SPA).';
                alert(errorText);
                if (reloadPage)
                    window.location.href = ""; // reload from root
            }
        Breakdown._IsInErrorHandling_ = false;
    }
} // Breakdown
Breakdown._UseDefaultErrorReporting_ = false;
Breakdown._IsInErrorHandling_ = false;
Breakdown._DamagedBehaviour_ = false;
//==================================================================================================
// BREAKDOWN — FUNCTIONS:
//--------------------------------------------------------------------------------------------------
function Breakdown_ShowWasmError(message, reloadCurrentPage = false) {
    Breakdown.ShowWasmError(message, reloadCurrentPage);
}
//==================================================================================================
//# sourceMappingURL=Breakdown.js.map