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

/** Confirm receipt popup (section 2.12): dimmed page in normal flow + centered card. */
export default function BizCoinvestConfirm() {
  const { goBack, params, navigate } = useApp();
  const op = bizOpportunities[0];
  const collected = bizCoinvestPayments.reduce((sum, c) => sum + c.amount, 0);
  const target: BizCoinvestPayment =
    bizCoinvestPayments.find((c) => c.id === params.requestId) ?? bizCoinvestPayments[0];

  return (
    <div className="relative min-h-full bg-background-50">
      {/* Payments context behind the popup (normal flow, not fixed, not interactive) */}
      <div className="px-4 py-5 space-y-4 pointer-events-none" aria-hidden>
        <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-[18px] font-bold text-foreground-950 mt-0.5 whitespace-nowrap">{fmt(collected)} ر.س</p>
        </div>
        <CoinvestPaymentsList />
      </div>

      <div className="absolute inset-0 bg-foreground-950/45" />

      <div className="absolute inset-0 z-10 flex items-center justify-center px-6">
        <div className="w-full max-w-[320px] rounded-[22px] bg-background-50 p-5 animate-fade-in">
          <div className="w-14 h-14 rounded-full bg-accent-100 flex items-center justify-center mx-auto">
            <i className="ri-check-double-line text-[28px] text-accent-700 leading-none" />
          </div>
          <h3 className="text-[15px] font-bold text-foreground-950 text-center mt-3 leading-relaxed">
            تأكيد استلام مبلغ {fmt(target.amount)} ر.س من {target.investor}؟
          </h3>

          <div className="mt-5 space-y-2.5">
            <button
              type="button"
              onClick={() => navigate("bizCoinvestPayments", { confirmed: target.id })}
              className="w-full h-[52px] rounded-[13px] bg-primary-500 text-background-50 text-[15px] font-semibold whitespace-nowrap cursor-pointer active:scale-[0.98] transition-transform"
            >
              تأكيد
            </button>
            <button
              type="button"
              onClick={goBack}
              className="w-full h-[52px] rounded-[13px] border border-background-300 text-foreground-900 text-[15px] font-semibold whitespace-nowrap cursor-pointer hover:bg-background-200"
            >
              إلغاء
            </button>
          </div>
        </div>
      </div>
    </div>
  );
}