import { jsx, jsxs } from "react/jsx-runtime";
import React from "react";
import { Box, Text } from "ink";
import { logger } from "@dexto/core";
class ErrorBoundary extends React.Component {
  constructor(props) {
    super(props);
    this.state = { hasError: false, error: null };
  }
  static getDerivedStateFromError(error) {
    return { hasError: true, error };
  }
  componentDidCatch(error, errorInfo) {
    logger.error(`Error in ErrorBoundary: ${error.message}`, {
      error,
      componentStack: errorInfo.componentStack
    });
  }
  render() {
    if (this.state.hasError) {
      return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", padding: 1, borderStyle: "round", borderColor: "red", children: [
        /* @__PURE__ */ jsx(Text, { color: "red", bold: true, children: "CLI Error" }),
        /* @__PURE__ */ jsx(Text, { color: "red", children: this.state.error?.message || "Unknown error" }),
        /* @__PURE__ */ jsx(Text, { color: "yellowBright", children: "Press Ctrl+C to exit" })
      ] });
    }
    return this.props.children;
  }
}
export {
  ErrorBoundary
};
