import { Box, TextButton, Text, } from '@wix/design-system';
import { isWixPatternsError, } from '@wix/bex-core';
import React from 'react';
import { isErrorDetailsHttpError, isHttpError } from '@wix/bex-core/util';
export function getExportModalErrorProps({ renderError, state, }) {
    const { exportStatus: { error: _error }, translate: t, errorHandler, } = state;
    const error = isWixPatternsError(_error)
        ? _error.originalException
        : _error;
    const details = isErrorDetailsHttpError(error) ? error.response.data : null;
    const applicationErrorCode = details?.applicationError?.code;
    const applicationErrorData = details?.applicationError?.data;
    if (!isHttpError(error)) {
        return {};
    }
    if (applicationErrorCode === 'method_endpoint_permission_denied') {
        return {
            children: (React.createElement(Box, { direction: "vertical" },
                React.createElement(Text, { widows: true }, t('cairo.export.noPermissionsMessage')),
                React.createElement(TextButton, { dataHook: "export-error-message-action", as: "a", href: "https://support.wix.com/en/article/roles-permissions-overview", target: "_blank" }, t('cairo.export.noPermissionsCTA')))),
        };
    }
    if (applicationErrorCode === 'media_generate_signed_url' ||
        applicationErrorCode === 'media_appender_completion' ||
        applicationErrorCode === 'async_job_infra') {
        return {
            children: (React.createElement(Box, { direction: "vertical" },
                React.createElement(Text, { widows: true }, t('cairo.export.databaseIssueMessage')),
                React.createElement(TextButton, { dataHook: "export-error-message-action", as: "a", href: "https://www.wix.com/contact", target: "_blank" }, t('cairo.error.contactSupport.cta')))),
        };
    }
    if (applicationErrorCode === 'max_polling_stale_job') {
        return {
            children: (React.createElement(Box, { direction: "vertical" },
                React.createElement(Text, { widows: true }, t('cairo.export.overloadErrorMessage')),
                React.createElement(TextButton, { dataHook: "export-error-message-action", as: "a", onClick: state.onRetryExportToClick }, t('cairo.export.tryAgain')))),
        };
    }
    if (applicationErrorCode === 'offline') {
        return {
            title: t('cairo.connection.error.title'),
            children: React.createElement(Text, { widows: true }, t('cairo.export.offlineMessage')),
        };
    }
    if (applicationErrorCode === 'grpc_query_target_internal') {
        return {
            children: (React.createElement(Box, { direction: "vertical" },
                React.createElement(Text, { widows: true }, t('cairo.export.serverErrorMessage')),
                React.createElement(TextButton, { dataHook: "export-error-message-action", as: "a", href: "https://www.wix.com/contact", target: "_blank" }, t('cairo.error.contactSupport.cta')))),
            ...renderError?.(applicationErrorData),
        };
    }
    const resolvedError = errorHandler.getResolvedError?.(error);
    return {
        children: (React.createElement(Box, { direction: "vertical" },
            React.createElement(Text, { widows: true }, resolvedError?.message),
            resolvedError?.action && (React.createElement(TextButton, { dataHook: "export-error-message-action", as: "a", onClick: resolvedError?.action?.onClick }, resolvedError?.action?.text)))),
    };
}
//# sourceMappingURL=getExportModalErrorProps.js.map