"use client";

import { createContext, useContext } from "react";
import type { DashboardMode } from "@/lib/dashboardMode";
import BuyerDashboard from "./BuyerDashboard";
import SellerDashboard from "./SellerDashboard";

/** Provided by `DashboardLayout`, which owns the Buying / Selling switch. */
export const DashboardModeContext = createContext<DashboardMode>("sell");

export function useDashboardMode(): DashboardMode {
  return useContext(DashboardModeContext);
}

/**
 * A buyer approved as a seller gets one dashboard at a time: the side the
 * switch is on. Both used to render on one long page.
 */
export function BuyerSellerDashboard() {
  return useDashboardMode() === "sell" ? <SellerDashboard /> : <BuyerDashboard title="Buyer Dashboard" />;
}
