import React, { FC, ReactElement } from "react";
import { render, RenderOptions } from "@testing-library/react";
import LocalLogicClient from "@local-logic/client";

import { LocalLogicProvider } from "../context";

interface WrapperProps {
  children: React.ReactNode;
}

const client = LocalLogicClient("123");
const frClient = LocalLogicClient("123", { locale: "fr" });

const Wrapper: FC<WrapperProps> = ({ children }) => (
  <LocalLogicProvider client={client}>{children}</LocalLogicProvider>
);

const FRWrapper: FC<WrapperProps> = ({ children }) => (
  <LocalLogicProvider client={frClient}>{children}</LocalLogicProvider>
);

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const customRender: any = (
  ui: ReactElement,
  options?: Omit<RenderOptions, "wrapper">
) =>
  render(ui, {
    wrapper: ({ children }) => Wrapper({ children }),
    ...options,
  });

export * from "@testing-library/react";
export { customRender as render, Wrapper as wrapper, FRWrapper as frWrapper };
