// test-utils.js
import React from 'react'
import type { RenderResult } from '@testing-library/react'
import { render as rtlRender } from '@testing-library/react'
import { IntlProvider } from 'react-intl'

function render(
    ui: Parameters<typeof rtlRender>[0],
    {
        locale = 'en',
        wrapper: IncomingWrapper,
        ...renderOptions
    }: Parameters<typeof rtlRender>[1] & { locale?: string } = {}
): RenderResult {
    function Wrapper({ children }: { children: React.ReactNode }) {
        return (
            <IntlProvider locale={locale}>
                {IncomingWrapper ? (
                    <IncomingWrapper>{children}</IncomingWrapper>
                ) : (
                    children
                )}
            </IntlProvider>
        )
    }
    return rtlRender(ui, { wrapper: Wrapper, ...renderOptions })
}

// re-export everything
export * from '@testing-library/react'

// override render method
export { render }
