import { useState } from "react";
import { useApp } from "@/pages/app/AppContext";
import { BackHeader, Btn } from "@/pages/app/components/ui";
import { fmt } from "@/pages/app/components/biz/BizUI";
import { bizCoinvestPayments } from "@/mocks/dshnBizDeals";
import { bizProofImage } from "@/mocks/dshnBizPartners";

/** Proof image view (zoomable) + "تأكيد الاستلام" for a committed co-investor (section 2.12). */
export default function BizCoinvestProof() {
  const { goBack, params, navigate } = useApp();
  const investor = bizCoinvestPayments.find((c) => c.id === params.requestId) ?? bizCoinvestPayments[0];
  const [zoom, setZoom] = useState(false);

  return (
    <div className="min-h-full flex flex-col bg-background-50">
      <BackHeader title="عرض الإثبات" onBack={goBack} />

      <div className="flex-1 px-4 py-5 space-y-4">
        <div className="rounded-[20px] bg-background-100 border border-background-200 p-4">
          <div className="flex items-center gap-3">
            <div className="w-11 h-11 rounded-full overflow-hidden bg-background-200 shrink-0">
              <img src={investor.avatar} alt={investor.investor} className="w-full h-full object-cover object-top" />
            </div>
            <div className="min-w-0">
              <p className="text-[13.5px] font-semibold text-foreground-950 truncate">{investor.investor}</p>
              <p className="text-[12.5px] font-bold text-foreground-950 mt-0.5 whitespace-nowrap">
                {fmt(investor.amount)} <span className="text-[11px] font-semibold">ر.س</span>
              </p>
            </div>
          </div>
        </div>

        <button
          type="button"
          onClick={() => setZoom((z) => !z)}
          className="block w-full rounded-[18px] overflow-hidden bg-background-200 border border-background-200 cursor-pointer"
        >
          <img
            src={bizProofImage}
            alt="إثبات الدفع"
            className={zoom ? "w-full h-[420px] object-contain bg-foreground-950" : "w-full h-[220px] object-cover object-top"}
          />
        </button>
      </div>

      <div className="sticky bottom-0 z-30 px-4 py-4 bg-background-50 border-t border-background-200/70">
        <Btn full onClick={() => navigate("bizCoinvestConfirm", { requestId: investor.id })}>
          <i className="ri-check-double-line text-[17px] leading-none" />
          تأكيد الاستلام
        </Btn>
      </div>
    </div>
  );
}