import { redirect } from "next/navigation";

type Props = {
  searchParams?: Promise<Record<string, string | string[] | undefined>>;
};

export default async function HorseDetailsRedirectPage({ searchParams }: Props) {
  const locale = "ar";
  const sp = searchParams ? await searchParams : undefined;

  const qs = new URLSearchParams();
  if (sp) {
    for (const [key, value] of Object.entries(sp)) {
      if (typeof value === "string") {
        qs.set(key, value);
      } else if (Array.isArray(value)) {
        for (const v of value) {
          if (typeof v === "string") qs.append(key, v);
        }
      }
    }
  }

  const queryString = qs.toString();
  const url = queryString
    ? `/${locale}/horse-details?${queryString}`
    : `/${locale}/horse-details`;

  redirect(url);
}
