"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.errorMessageBlock = errorMessageBlock;
/**
 * Create an error message block
 * @param dom The DOM on which dom.createElement will be called
 * @param err The error message string to display (or an error object)
 * @param backgroundColor Background color. Default: '#fee'
 * @param err2 Is the second param is a string, you can put the original Error in here
 * @returns A div element with the err string
 *
 * This will return a DOM element you can put in the UI as a notice for the user
 *  Meanwhile the stack is dumped to the console for the developer, so you actually know
 *  where it happened!
 */
/* eslint-disable no-console */
const widgets_1 = require("../widgets");
const style_1 = require("../style");
const styleConstants_1 = __importDefault(require("../styleConstants"));
function errorMessageBlock(dom, err, backgroundColor, err2) {
    const div = dom.createElement('div');
    /* tslint:disable-next-line */ // Too complex for TS?
    // @ts-ignore
    const errorObject = err2 || err instanceof Error ? err : null;
    if (errorObject) {
        console.error(`errorMessageBlock: ${errorObject} at: ${errorObject.stack || '??'}`, errorObject); // @@ pick one
        div.textContent = errorObject.message;
    }
    else {
        div.textContent = err;
    }
    div.appendChild((0, widgets_1.cancelButton)(dom, () => { if (div.parentNode)
        div.parentNode.removeChild(div); }))
        .style = style_1.style.errorCancelButton;
    div.setAttribute('style', style_1.style.errorMessageBlockStyle);
    div.style.backgroundColor = (backgroundColor || styleConstants_1.default.defaultErrorBackgroundColor);
    return div;
}
//# sourceMappingURL=error.js.map