import { useApp } from "@/pages/app/AppContext";
import { BackHeader } from "@/pages/app/components/ui";
import { fmt } from "@/pages/app/components/biz/BizUI";
import { CoinvestPaymentsList } from "@/pages/app/components/biz/CoinvestPaymentsList";
import { bizCoinvestPayments } from "@/mocks/dshnBizDeals";
import { bizOpportunities } from "@/mocks/dshnBizOwner";

/** Committed investors' payments list (section 2.12). */
export default function BizCoinvestPayments() {
  const { goBack, params, navigate } = useApp();
  const op = bizOpportunities[0];
  const collected = bizCoinvestPayments.reduce((sum, c) => sum + c.amount, 0);
  const confirmedIds = params.confirmed ? params.confirmed.split(",") : [];

  return (
    <div className="min-h-full pb-8 bg-background-50">
      <BackHeader title="دفعات المستثمرين" onBack={goBack} />

      <div className="px-4 py-5 space-y-4">
        {/* Summary: opportunity category + collected amount */}
        <div className="rounded-[18px] bg-accent-50 border border-accent-200 p-4">
          <p className="text-[13px] font-semibold text-foreground-950 truncate">{op.category}</p>
          <p className="text-[11px] text-accent-800 mt-1.5">المبلغ المجموع</p>
          <p className="text-[20px] font-bold text-foreground-950 mt-0.5 whitespace-nowrap">
            {fmt(collected)} <span className="text-[12px] font-semibold">ر.س</span>
          </p>
        </div>

        <CoinvestPaymentsList
          confirmedIds={confirmedIds}
          onProof={(id) => navigate("bizCoinvestProof", { requestId: id })}
          onConfirm={(id) => navigate("bizCoinvestConfirm", { requestId: id })}
        />

        {/* Side scenario: manual follow-up for those who didn't upload a proof */}
        <div className="flex items-start gap-2 rounded-[14px] bg-background-100 border border-background-200 px-3.5 py-3">
          <i className="ri-information-line text-[16px] text-foreground-500 leading-none mt-0.5" />
          <span className="text-[11px] text-foreground-600 leading-relaxed">
            المتابعة مع الملتزمين الذين لم يرفعوا إثبات الدفع تتم بشكل مباشر بين الطرفين.
          </span>
        </div>
      </div>
    </div>
  );
}