import { __assign, __extends } from "tslib";
import React from 'react';
var ErrorBoundary = /** @class */ (function (_super) {
    __extends(ErrorBoundary, _super);
    function ErrorBoundary() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.state = { error: null };
        return _this;
    }
    // capture error
    ErrorBoundary.getDerivedStateFromError = function (error) {
        return { error: error };
    };
    ErrorBoundary.prototype.componentDidCatch = function (error, info) {
        var _a, _b;
        console.error('组件边界错误', error);
        (_b = (_a = this.props).onError) === null || _b === void 0 ? void 0 : _b.call(_a, error, info);
    };
    ErrorBoundary.prototype.render = function () {
        var error = this.state.error;
        // @ts-expect-error ts(2339) (at least one of these will be defined though, and we check for their existence)
        var _a = this.props, fallbackRender = _a.fallbackRender, FallbackComponent = _a.FallbackComponent, fallback = _a.fallback;
        if (error !== null) {
            var props = {
                error: error,
            };
            if (React.isValidElement(fallback)) {
                return fallback;
            }
            if (typeof fallbackRender === 'function') {
                return fallbackRender(props);
            }
            if (FallbackComponent) {
                return React.createElement(FallbackComponent, __assign({}, props));
            }
            return "Error Render: ".concat(error === null || error === void 0 ? void 0 : error.message);
        }
        return this.props.children;
    };
    return ErrorBoundary;
}(React.Component));
export { ErrorBoundary };
export function createErrorFallback(cmpKey, id) {
    return function ComponentErrorFallback(props) {
        var isComponentError = true;
        var tipsContent = '组件错误';
        return (React.createElement("div", { className: "component-error-box", style: {
                width: 169,
                height: 91,
                background: 'rgb(241, 242, 245)',
                display: 'flex',
                justifyContent: 'center',
                alignItems: 'center',
                margin: '6px',
            }, title: isComponentError
                ? "\u7EC4\u4EF6".concat(cmpKey, " ").concat(id, "\u53D1\u751F\u4E86\u9519\u8BEF\uFF0C\u8BF7\u786E\u4FDD\u60A8\u4F7F\u7528\u6B63\u786E\u7684\u7EC4\u4EF6\u5E93\u6216\u8054\u7CFB\u7EC4\u4EF6\u4F5C\u8005\u9519\u8BEF\u4FE1\u606F\uFF1A").concat(props.error)
                : tipsContent },
            React.createElement("div", { className: "component-error-box-icon", style: {
                    height: 32,
                    width: 32,
                    backgroundSize: '100% 100%',
                    backgroundRepeat: 'no-repeat',
                    backgroundImage: 'url(https://imgcache.qq.com/qcloud/lowcode/static/ide/component-fail.svg)',
                } })));
    };
}
export function ComponentNotFound(_a) {
    var _b = _a.module, module = _b === void 0 ? '' : _b, component = _a.component;
    return (React.createElement("div", { style: { color: 'red' } },
        "\u7EC4\u4EF6",
        React.createElement("em", null, "".concat(module, ":").concat(component)),
        "\u672A\u627E\u5230"));
}
//# sourceMappingURL=error.js.map