import { useApp } from "@/pages/app/AppContext";
import { Badge, Btn } from "@/pages/app/components/ui";
import { investorOpportunities } from "@/mocks/dshnInvestor";

function fmt(n: number) {
  return n.toLocaleString("en-US");
}

function fmtPct(n: number) {
  return String(Math.round(n * 100) / 100);
}

/** E) Success screen after the co-investment commitment is submitted. */
export default function CoinvestSuccessBody() {
  const { params, navigate } = useApp();
  const opp = investorOpportunities.find((o) => o.id === "op-inv-1") ?? investorOpportunities[0];
  const target = opp.target ?? opp.amount;
  const amount = Number(params.amount) || 100000;
  const share = (amount / target) * opp.equity;

  return (
    <div className="flex min-h-full flex-col bg-background-50">
      <div className="flex-1 px-4 pt-10 pb-6">
        <div className="flex flex-col items-center text-center">
          <div className="w-20 h-20 rounded-full bg-accent-100 flex items-center justify-center">
            <i className="ri-check-line text-[42px] text-accent-700 leading-none" />
          </div>
          <h2 className="text-[20px] font-bold text-foreground-950 mt-5 leading-snug">
            تم إرسال التزامك بنجاح
          </h2>
          <p className="text-[13px] text-foreground-600 mt-2 max-w-[300px] leading-relaxed">
            تم إنشاء طلب جديد بحالة «طلب جديد» بانتظار رد صاحب المنشأة. يمكنك متابعة الحالة والتفاوض من قسم
            «المتابعة».
          </p>
        </div>

        <div className="mt-6 rounded-[20px] bg-background-100 border border-background-200 p-4 space-y-3.5">
          <div className="flex items-center justify-between gap-3">
            <span className="text-[12.5px] text-foreground-600 whitespace-nowrap">المبلغ الملتزم به</span>
            <span className="text-[13px] font-bold text-foreground-950 whitespace-nowrap">
              {fmt(amount)} ر.س
            </span>
          </div>
          <div className="h-px bg-background-200" />
          <div className="flex items-center justify-between gap-3">
            <span className="text-[12.5px] text-foreground-600 whitespace-nowrap">النصيب المتوقع</span>
            <span className="text-[13px] font-bold text-foreground-950 whitespace-nowrap">
              {fmtPct(share)}%
            </span>
          </div>
          <div className="h-px bg-background-200" />
          <div className="flex items-center justify-between gap-3">
            <span className="text-[12.5px] text-foreground-600 whitespace-nowrap">حالة الطلب</span>
            <Badge tone="neutral">طلب جديد</Badge>
          </div>
        </div>

        <div className="mt-6 space-y-2.5">
          <Btn full onClick={() => navigate("invFollowing")}>
            الذهاب إلى المتابعة
          </Btn>
          <Btn
            full
            variant="secondary"
            onClick={() => navigate("invOpportunity", { opportunityId: opp.id })}
          >
            العودة للفرصة
          </Btn>
        </div>
      </div>
    </div>
  );
}