"use client";

import type { DriftAllocationComparison } from "@/app/customer/[tenant]/settings/_lib/tenant-settings-server-api";

import { AllocationCharts } from "./allocation-charts";
import { DetailedBreakdownTable } from "./detailed-breakdown-table";
import { GapSummaryTables } from "./gap-summary-tables";
import { SuggestedReallocationCard } from "./suggested-reallocation-card";

import type { DriftAllocationConstituent } from "./map-drift-payload";

type RealAllocationSectionProps = {
  comparison: DriftAllocationComparison[];
  ruleConstituents: DriftAllocationConstituent[][];
  totalPortfolioValue: number;
  reportingCode: string;
  showCharts?: boolean;
  showTotalCard?: boolean;
};

export function RealAllocationSection({
  comparison,
  ruleConstituents,
  totalPortfolioValue,
  reportingCode,
  showCharts = true,
  showTotalCard = true,
}: RealAllocationSectionProps) {
  if (!comparison.length) {
    return (
      <div className="rounded-2xl border border-dashed border-border/80 p-10 text-center text-muted-foreground text-sm">
        No target allocation rules found. Define targets in Drift Settings, then refresh this report.
      </div>
    );
  }

  return (
    <div className="space-y-6">
      <SuggestedReallocationCard
        comparison={comparison}
        totalPortfolioValue={totalPortfolioValue}
        reportingCode={reportingCode}
        showTotalBadge={showTotalCard}
      />

      {showCharts ? <AllocationCharts comparison={comparison} mode="real" layout="full" /> : null}

      <GapSummaryTables
        comparison={comparison}
        totalPortfolioValue={totalPortfolioValue}
        reportingCode={reportingCode}
      />

      <DetailedBreakdownTable
        comparison={comparison}
        ruleConstituents={ruleConstituents}
        reportingCode={reportingCode}
      />
    </div>
  );
}
