import { useApp } from "@/pages/app/AppContext";
import { BackHeader, Badge, Btn } from "@/pages/app/components/ui";
import NegStatusFlow from "@/pages/app/components/biz/NegStatusFlow";
import { bizNegotiations } from "@/mocks/dshnBizDeals";

/**
 * Section 2.13 — Negotiation request in the "قيد التواصل والتفاوض" (negotiating) state.
 *
 * Mirrors the agreed details layout: status card, customer card, requested products
 * (thumbnail + name + quantity, no prices yet) and two CTAs inside the content:
 * open the chat (primary) and upload an invoice (outlined). No bottom nav.
 */
export default function BizNegotiationNegotiating() {
  const { goBack, params, navigate } = useApp();

  const req =
    bizNegotiations.find((n) => n.id === params.requestId && n.status === "talking") ??
    bizNegotiations.find((n) => n.status === "talking") ??
    bizNegotiations[0];

  return (
    <div className="min-h-full pb-8 bg-background-50">
      <BackHeader title="تفاصيل طلب التفاوض" onBack={goBack} />

      <div className="px-4 py-5 space-y-4">
        <NegStatusFlow status="talking" />

        {/* Status card */}
        <div className="rounded-[20px] bg-background-100 border border-background-200 p-4">
          <Badge tone="warn" icon="ri-chat-voice-line">
            قيد التواصل والتفاوض
          </Badge>
          <p className="text-[13px] text-foreground-700 leading-relaxed mt-3">
            تم قبول الطلب، تفاوض مع العميل على الأسعار ثم ارفع الفاتورة.
          </p>
        </div>

        {/* Customer card — basic customer data only */}
        <div className="rounded-[20px] bg-background-100 border border-background-200 p-4 flex items-center gap-3">
          <div className="w-14 h-14 rounded-full overflow-hidden bg-background-200 shrink-0">
            <img src={req.avatar} alt={req.customer} className="w-full h-full object-cover object-top" />
          </div>
          <div className="min-w-0">
            <h2 className="text-[15px] font-semibold text-foreground-950 truncate">{req.customer}</h2>
            <p className="text-[11.5px] text-foreground-600 mt-0.5">عميل • {req.city}</p>
          </div>
        </div>

        {/* Requested products — no prices yet */}
        <div className="rounded-[18px] bg-background-100 border border-background-200 p-4">
          <p className="text-[13px] font-semibold text-foreground-950 mb-1">المنتجات المطلوبة</p>
          <div className="divide-y divide-background-200">
            {req.items.map((it) => (
              <div key={it.name} className="flex items-center gap-3 py-3">
                <div className="w-12 h-12 rounded-[12px] overflow-hidden bg-background-200 shrink-0 flex items-center justify-center">
                  {it.image ? (
                    <img src={it.image} alt={it.name} className="w-full h-full object-cover object-top" />
                  ) : (
                    <i className="ri-image-2-line text-[20px] text-foreground-500 leading-none" />
                  )}
                </div>
                <div className="min-w-0 flex-1">
                  <p className="text-[12.5px] font-medium text-foreground-950 leading-snug">{it.name}</p>
                  <p className="text-[11px] text-foreground-600 mt-1">الكمية: {it.qty}</p>
                </div>
                <span className="shrink-0 inline-flex items-center rounded-full bg-secondary-100 text-secondary-900 px-2.5 py-1 text-[10.5px] font-semibold whitespace-nowrap">
                  السعر حسب التفاوض
                </span>
              </div>
            ))}
          </div>
        </div>

        {/* CTAs inside the content (stacked, 12px gap) */}
        <div className="space-y-3">
          <Btn full onClick={() => navigate("bizNegotiationChat", { requestId: req.id })}>
            <i className="ri-chat-3-line text-[18px] leading-none" />
            فتح المحادثة
          </Btn>
          <Btn variant="secondary" full onClick={() => navigate("bizInvoiceForm", { requestId: req.id })}>
            <i className="ri-file-add-line text-[18px] leading-none" />
            رفع فاتورة
          </Btn>
        </div>
      </div>
    </div>
  );
}