"use client";

import type { ReactNode } from "react";
import { usePathname } from "next/navigation";
import { AdminShell } from "@/components/admin-shell";
import { productAreas, runtimeSurface } from "@/lib/platform";

type AdminShellFrameProps = {
  children: ReactNode;
  authEnabled: boolean;
};

function getAdminCopy(pathname: string) {
  if (pathname === "/admin") {
    return {
      title: "Ballbox admin",
      description: "Control plane del host app con métricas y accesos por dominio.",
    };
  }

  if (pathname === "/admin/login") {
    return {
      title: "Admin access",
      description: "Entrá al control plane compartido de Ballbox.",
    };
  }

  const product = productAreas.find((area) => area.href === pathname);
  if (product) {
    return {
      title: product.title,
      description: product.summary,
    };
  }

  if (pathname === runtimeSurface.href) {
    return {
      title: "Screens Runtime",
      description: "Superficie admin para estado y acceso al runtime de pantallas.",
    };
  }

  return {
    title: "Ballbox admin",
    description: "Una sola app host para operar Ballbox por dominio.",
  };
}

export function AdminShellFrame({ children, authEnabled }: AdminShellFrameProps) {
  const pathname = usePathname();
  const copy = getAdminCopy(pathname);

  return (
    <AdminShell
      title={copy.title}
      description={copy.description}
      currentPath={pathname}
      authEnabled={authEnabled}
    >
      {children}
    </AdminShell>
  );
}
