import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { useOneUIContext } from "../../context/OneUIProvider";
import AdaptiveDialog from "../AdaptiveDialog";
import Button from "../Button";
import Loader from "../Loader";
import Text from "../Text";
/**
 * This is a generic implementation of the loading, and error handling
 *
 * This component wraps your content and shows a loading spinner while data is being fetched.
 * If an error occurs, it displays an error message with a retry button.
 * It handles both the loading state and error state in one place.
 **/
export default function AsyncWrapper({ loading, error, onClose, onRetry, children, }) {
    const { LoadingComponent = Loader, messages, } = useOneUIContext().component.asyncWrapper;
    return (_jsxs(_Fragment, { children: [children, _jsxs(AdaptiveDialog, { open: error, onClose: onClose, children: [_jsx(Text, { type: "highlightTitle", children: messages.error.title }), _jsx(Button, { onClick: () => onRetry(), children: messages.error.retryBtn })] }), loading ? _jsx(LoadingComponent, {}) : null] }));
}
//# sourceMappingURL=AsyncWrapper.js.map