import { useState } from "react";
import { useApp } from "@/pages/app/AppContext";
import { BackHeader, Btn } from "@/pages/app/components/ui";
import { Field, TextInput } from "@/pages/app/components/bo/BoUI";
import { fmt } from "@/pages/app/components/biz/BizUI";
import { bizCoinvestSnapshot } from "@/mocks/dshnBizDeals";
import { bizOpportunities } from "@/mocks/dshnBizOwner";

export default function BizCoinvestExtend() {
  const { goBack, navigate } = useApp();
  const op = bizOpportunities[0];
  const { collected, target } = bizCoinvestSnapshot;

  const [date, setDate] = useState("30 ديسمبر 2025");
  const [time, setTime] = useState("23:59");

  const valid = date.trim() !== "" && time.trim() !== "";

  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-[16px] bg-background-100 border border-background-200 p-4">
          <p className="text-[13px] font-semibold text-foreground-950">{op.category}</p>
          <p className="text-[11.5px] text-foreground-600 mt-1">
            تم جمع {fmt(collected)} من أصل {fmt(target)} ر.س
          </p>
        </div>

        <div className="grid grid-cols-2 gap-3">
          <Field label="تاريخ الانتهاء الجديد" required>
            <TextInput value={date} onChange={setDate} placeholder="30/12/2025" />
          </Field>
          <Field label="الوقت" required>
            <TextInput value={time} onChange={setTime} placeholder="23:59" dir="ltr" />
          </Field>
        </div>

        <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-[17px] text-foreground-500 leading-none mt-0.5" />
          <span className="text-[11.5px] text-foreground-600 leading-relaxed">
            عند بلوغ الهدف تُغلق الفرصة تلقائيًا ويُطلب من جميع المستثمرين الملزمين الدفع.
          </span>
        </div>
      </div>

      <div className="sticky bottom-0 z-30 px-4 py-4 bg-background-50 border-t border-background-200/70">
        <Btn full disabled={!valid} onClick={() => navigate("bizOpportunities")}>
          تأكيد التمديد
        </Btn>
      </div>
    </div>
  );
}