"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.APIError = void 0;
const contexts_1 = require("../contexts/index.js");
const ui_1 = require("@roomstay/ui");
const BookingAPI_1 = __importDefault(require("../api/BookingAPI"));
const RoomstayThemeEngine_1 = __importDefault(require("../providers/RoomstayThemeEngine"));
const Translation_1 = require("../translations/Translation");
const RoomstayError_1 = require("./RoomstayError");
class APIError extends RoomstayError_1.RoomstayError {
    constructor(message) {
        super(message !== null && message !== void 0 ? message : 'Failed to load API data');
    }
    toString() {
        // We'll fetch the error API quickly to see if there is any scheduled maintenance.
        BookingAPI_1.default.Error.getStatus().then((response) => {
            var _a, _b;
            if (response) {
                contexts_1.ErrorHandler.add({
                    title: (_a = response.title) !== null && _a !== void 0 ? _a : (_b = RoomstayThemeEngine_1.default.translation) === null || _b === void 0 ? void 0 : _b.call(RoomstayThemeEngine_1.default, Translation_1.Translation.Misc.APIErrorTitle),
                    message: response.message,
                    icon: ui_1.IconType.Error,
                });
            }
        });
    }
}
exports.APIError = APIError;
//# sourceMappingURL=APIError.js.map