"use client";

import { AlternativeInvestment } from "@/components/datatable/listotherassets/columns";
import { formatNumeric, formatDisplay, getAmountColor } from "@/lib/common";
import { RecordModal } from "@/components/cash/RecordModal";

interface OtherAssetDetailModalProps {
  record: AlternativeInvestment;
  onClose: () => void;
  onEdit: () => void;
  onDelete?: () => void;
}

/**
 * Detail dialog for alternative investments.
 *
 * This was a full second copy of `RecordModal` — same overlay, same header,
 * same metric tiles, same detail grid, same footer — roughly 130 duplicated
 * lines that had already drifted (its own close-button style, its own delete
 * button, no `extraContent` support). It now delegates, so it inherits the
 * dialog accessibility and stays visually identical to the other 14 detail
 * modals by construction.
 */

const getDetailItems = (record: AlternativeInvestment) => [
  { label: "Placement Date", value: formatDisplay(record.t_date) },
  { label: "Bank", value: formatDisplay(record.bank_id) },
  { label: "Execution Type", value: formatDisplay(record.e_t) },
  { label: "Transaction Type", value: formatDisplay(record.t_o_t) },
  { label: "Currency", value: formatDisplay(record.purchase_currency_code) },
  { label: "Asset Type", value: formatDisplay(record.asset_type_t) },
];

export const OtherAssetDetailModal = ({
  record,
  onClose,
  onEdit,
  onDelete,
}: OtherAssetDetailModalProps) => {
  const metrics = [
    {
      label: "Total Amount",
      value: formatNumeric(record.amount),
      colorClass: getAmountColor(record.amount),
    },
    {
      label: "Placement Date",
      value: formatDisplay(record.t_date),
      colorClass: "text-foreground",
    },
    {
      label: "Transaction Type",
      value: formatDisplay(record.t_o_t),
      colorClass: "text-foreground",
    },
  ];

  return (
    <RecordModal
      record={record}
      onClose={onClose}
      onEdit={onEdit}
      onDelete={onDelete}
      title="Other asset overview"
      subtitle={record.ticker || "—"}
      metrics={metrics}
      detailItems={getDetailItems(record)}
    />
  );
};
