import { useApp } from "@/pages/app/AppContext";
import { BackHeader, Badge } from "@/pages/app/components/ui";
import { BizOpportunityReadonly } from "@/pages/app/components/biz/BizUI";
import Countdown from "@/pages/app/components/bo/Countdown";
import { bizOpportunities } from "@/mocks/dshnBizOwner";

/** Published timed opportunity — countdown + red-tint cancel (section 2.7). */
export default function BizOpportunityTimed() {
  const { goBack, navigate } = useApp();
  const op =
    bizOpportunities.find((o) => o.status === "published" && o.endDate) ?? bizOpportunities[0];
  const target = Date.now() + 51 * 86400000;

  return (
    <div className="min-h-full flex flex-col bg-background-50">
      <BackHeader title="الفرصة الاستثمارية" onBack={goBack} action={<Badge tone="mint">منشورة</Badge>} />

      <div className="flex-1 px-4 py-5 space-y-4">
        <div className="rounded-[16px] bg-secondary-50 border border-secondary-200 p-4">
          <p className="text-[11.5px] text-foreground-600 mb-2">تنتهي الفرصة خلال</p>
          <Countdown target={target} />
        </div>

        <BizOpportunityReadonly op={op} />

        <p className="text-[11px] text-foreground-500 leading-relaxed text-center px-2">
          لا يمكن تعديل الفرصة بعد النشر، لتعديلها ألغِها وأنشئ فرصة جديدة
        </p>
      </div>

      <div className="sticky bottom-0 z-30 px-4 py-4 bg-background-50 border-t border-background-200/70">
        <button
          type="button"
          onClick={() => navigate("bizOpportunityCancel")}
          className="w-full h-[52px] rounded-[14px] bg-danger-50 border border-danger-200 text-danger-700 text-[15px] font-semibold flex items-center justify-center gap-2 whitespace-nowrap cursor-pointer active:scale-[0.98] transition-transform"
        >
          <i className="ri-close-circle-line text-[17px] leading-none" />
          إلغاء الفرصة
        </button>
      </div>
    </div>
  );
}