var __extends = this && this.__extends || function () {
  var _extendStatics = function extendStatics(d, b) {
    _extendStatics = Object.setPrototypeOf || {
      __proto__: []
    } instanceof Array && function (d, b) {
      d.__proto__ = b;
    } || function (d, b) {
      for (var p in b) {
        if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
      }
    };

    return _extendStatics(d, b);
  };

  return function (d, b) {
    if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");

    _extendStatics(d, b);

    function __() {
      this.constructor = d;
    }

    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  };
}();

import * as React from 'react';
import { toastOnTarget } from "../toast";
var globelToast;

var ErrorBoundaryNotify =
/** @class */
function (_super) {
  __extends(ErrorBoundaryNotify, _super);

  function ErrorBoundaryNotify(props) {
    var _this = _super.call(this, props) || this;

    _this.reload = function () {
      _this.setState({
        hasError: false
      });
    };

    _this.state = {
      hasError: false,
      errorMsg: ''
    };
    return _this;
  }

  ErrorBoundaryNotify.configToast = function (getContainer, prefix) {
    if (prefix === void 0) {
      prefix = 'boundary';
    }

    if (!globelToast) {
      requestAnimationFrame(function () {
        globelToast = toastOnTarget(getContainer, prefix);
      });
    }
  };

  ErrorBoundaryNotify.getDerivedStateFromError = function (error) {
    return {
      hasError: true,
      errorMsg: error.message
    };
  };

  ErrorBoundaryNotify.prototype.componentDidCatch = function (_error, errorInfo) {
    console.log('组件渲染失败Notify', errorInfo);
    var argProps = this.props.args;
    var errorMsg = this.state.errorMsg;
    var args = typeof argProps === 'function' ? argProps(errorMsg) : argProps;
    globelToast.error(args);
  };

  ErrorBoundaryNotify.prototype.render = function () {
    if (this.state.hasError) {
      return null;
    }

    return this.props.children;
  };

  return ErrorBoundaryNotify;
}(React.Component);

export default ErrorBoundaryNotify;

