"use client";

import { usePathname } from "next/navigation";
import { Toaster as HotToaster, type ToasterProps } from "react-hot-toast";

import { resolveLocale } from "@/lib/locale";

export function Toaster(props: ToasterProps) {
  const pathname = usePathname();
  const locale = resolveLocale(pathname.split("/")[1] || "de");
  const isArabic = locale === "ar";

  const toastClassName = `${isArabic ? "font-arabic tracking-normal" : "font-latin"} text-[13px] leading-5`;

  return (
    <HotToaster
      key={locale}
      {...props}
      position={props.position ?? (isArabic ? "top-right" : "top-left")}
      reverseOrder={props.reverseOrder ?? false}
      toastOptions={{
        ...props.toastOptions,
        className:
          props.toastOptions?.className ??
          toastClassName,
        style: {
          borderRadius: "36px",
          ...(props.toastOptions?.style ?? {}),
        },
      }}
    />
  );
}
