//
// Copyright 2025 DXOS.org
//
import React, { useMemo } from 'react';
import { Callout } from '@dxos/react-ui';
import { mx } from '@dxos/ui-theme';
export const ExceptionPanel = ({ objects }) => {
    const errorLogs = useMemo(() => {
        if (!objects?.length) {
            return [];
        }
        return objects
            .flatMap((event) => event.logs
            .filter((log) => log.level === 'error')
            .map((log) => ({
            ...log,
            eventId: event.id,
        })))
            .sort((a, b) => a.timestamp - b.timestamp);
    }, [objects]);
    if (errorLogs.length === 0) {
        return (React.createElement("div", { role: 'none', className: mx('flex is-full items-center justify-center m-4') },
            React.createElement(Callout.Root, null,
                React.createElement(Callout.Title, null, "No exceptions."))));
    }
    return (React.createElement("div", { className: mx('p-1 overflow-auto') }, errorLogs.map((log, index) => {
        const context = log.context;
        const time = new Date(log.timestamp).toLocaleString();
        const errorInfo = context?.err || {};
        const errorName = errorInfo._id || 'Error';
        const errorMessage = errorInfo.message || log.message;
        const stack = context?.stack;
        return (React.createElement("div", { key: `log-${index}`, className: 'mb-2 border border-red-200 dark:border-red-900 rounded overflow-hidden' },
            React.createElement("div", { className: 'p-2' },
                React.createElement("div", { className: 'flex justify-between items-start' },
                    React.createElement("div", { className: 'font-medium' }, errorName),
                    React.createElement("div", { className: 'text-xs font-mono opacity-80' }, time)),
                React.createElement("div", { className: 'mt-1 text-xs font-mono whitespace-pre-wrap' }, errorMessage)),
            stack && React.createElement("pre", { className: 'p-3 text-xs bg-neutral-50 dark:bg-neutral-900 overflow-auto' }, stack)));
    })));
};
//# sourceMappingURL=ExceptionPanel.js.map