import { render, type RenderOptions } from "@testing-library/react"
import React, { type ReactElement } from "react"

import { Lang } from "@scandic-hotels/common/constants/language"

import messages from "@/i18n/dictionaries/en.json"
import ClientIntlProvider from "@/i18n/Provider"

function AllTheProviders({ children }: { children: React.ReactNode }) {
  return (
    <ClientIntlProvider
      defaultLocale={Lang.en}
      locale={Lang.en}
      messages={messages}
    >
      {children}
    </ClientIntlProvider>
  )
}

const customRender = (
  ui: ReactElement,
  options?: Omit<RenderOptions, "wrapper">
) => render(ui, { wrapper: AllTheProviders, ...options })

export * from "@testing-library/react"
export { customRender as render }
