import { ArrowRight } from 'lucide-react';
import Link from 'next/link';

import { Card } from '@/components/ui/card';
import { formatMoney } from '@/lib/money';
import type { ShipmentListItem } from '@/lib/shipments';

/** Shows only what the tenant paid. Base cost and markup are never shown. */
export function CostSummaryCard({ shipment }: { shipment: ShipmentListItem }) {
  const total = shipment.chargedMinor ?? 0;
  return (
    <Card className="p-5 md:p-6">
      <h2 className="font-display text-h3 font-bold">Cost</h2>
      <dl className="mt-4 grid gap-2.5 text-small">
        <div className="flex justify-between gap-3">
          <dt className="text-muted-foreground">Shipping charge</dt>
          <dd className="font-semibold tabular-nums">{formatMoney(total, shipment.currency)}</dd>
        </div>
        {shipment.isInsured && shipment.insuredAmountMinor !== undefined ? (
          <div className="flex justify-between gap-3">
            <dt className="text-muted-foreground">Insured value</dt>
            <dd className="tabular-nums text-muted-foreground">{formatMoney(shipment.insuredAmountMinor, shipment.currency)}</dd>
          </div>
        ) : null}
        <div className="my-1 border-t border-dashed border-border-strong" aria-hidden="true" />
        <div className="flex items-end justify-between gap-3">
          <dt className="font-semibold">Total</dt>
          <dd className="font-display text-[28px] font-extrabold leading-none tracking-[-0.02em] tabular-nums">{formatMoney(total, shipment.currency)}</dd>
        </div>
      </dl>
      <Link href="/wallet" className="group mt-4 inline-flex items-center gap-1 text-small font-semibold text-primary underline-offset-4 hover:underline">
        View in wallet ledger
        <ArrowRight className="h-3.5 w-3.5 transition-transform group-hover:translate-x-0.5" aria-hidden="true" />
      </Link>
    </Card>
  );
}
