"use client";

import { useAppLanguage } from "@/contexts/LanguageProvider";
import { usePathname } from "next/navigation";
import { shouldUseLtrLayout } from "@/lib/i18n/pageDirection";
import { cn } from "@/lib/utils";

type LocalePageShellProps = {
  children: React.ReactNode;
  className?: string;
  /** Force LTR for this subtree when English is active */
  ltrWhenEnglish?: boolean;
};

/**
 * Wrap page content that should become LTR in English.
 * Page-by-page rollout will use ltrWhenEnglish on listed routes.
 */
export default function LocalePageShell({
  children,
  className,
  ltrWhenEnglish = true,
}: LocalePageShellProps) {
  const { language } = useAppLanguage();
  const pathname = usePathname();
  const useLtr =
    ltrWhenEnglish && shouldUseLtrLayout(pathname, language);

  return (
    <div
      dir={useLtr ? "ltr" : undefined}
      className={cn(useLtr && "locale-page-shell--ltr text-left", className)}
    >
      {children}
    </div>
  );
}
