import { CustomerPageShell } from "@/app/customer/_components/customer-page-shell";
import {
  parseCustomerRecordViewParams,
  type CustomerRecordViewPageProps,
} from "@/app/customer/_lib/parse-customer-record-view-params";

import { SwapsViewPage } from "../_components/swaps-view-page";
import { fetchSwapsViewPageData } from "../_lib/fetch-swaps-view-page";
import { requireCustomerPageAccess } from "@/app/customer/_lib/customer-page-guard";
import { CUSTOMER_ROUTE_KEYS } from "@/config/customer-route-keys";

export default async function SwapsRecordViewPage(props: CustomerRecordViewPageProps) {
  const { tenant, id, customerId, backHref } = await parseCustomerRecordViewParams(
    props,
    "/fx-currency/swaps",
  );
  await requireCustomerPageAccess(tenant, CUSTOMER_ROUTE_KEYS.swapsIndex);
  const data = await fetchSwapsViewPageData(tenant, id, customerId);

  return (
    <CustomerPageShell>
      <div className="px-1 py-2 sm:px-2">
        <SwapsViewPage tenant={tenant} data={data} backHref={backHref} />
      </div>
    </CustomerPageShell>
  );
}
