import type { LoaderFunctionArgs } from "react-router";
import PublicDashboardViewer from "./_client";

/**
 * Public share-link viewer at /public/dashboards/:token.
 *
 * The path matches what the backend's buildShareUrl mints from
 * ADMIN_CONSOLE_URL, and the route is registered outside root.layout — the
 * same treatment as the existing public EDM preview — so no console session is
 * required. The opaque token is the only credential.
 *
 * The loader deliberately does no resolution: it would have to forward the
 * token server-side to learn anything, and the client has to probe for the
 * password gate regardless. Keeping it here means one code path, and the token
 * never travels anywhere it doesn't already go.
 */
export function loader({ params }: LoaderFunctionArgs) {
  return { token: params.token ?? "" };
}

const Page = ({ loaderData }: { loaderData: { token: string } }) => (
  <PublicDashboardViewer token={loaderData.token} />
);

export default Page;
