import { useState } from "react";
import { useApp } from "@/pages/app/AppContext";
import { BackHeader, Btn } from "@/pages/app/components/ui";
import { Field, TextInput, UploadBox } from "@/pages/app/components/bo/BoUI";
import { bizPartnershipSides } from "@/mocks/dshnBizPartners";
import { useProductStore } from "@/pages/product/store";

const PLATFORM = {
  bank: "مصرف الراجحي",
  name: "شركة دشن للتقنية",
  iban: "SA03 8000 0000 6080 1016 7519",
};

/** Partnership transfer above the fixed limit — platform bank details + proof (section 2.21). */
export default function BizPartnerTransfer() {
  const { goBack, navigate, params } = useApp();
  const { partnershipById, submitPartnerPayment } = useProductStore();
  const id = String(params.partnerId ?? "pt3");
  const row = partnershipById(id);
  const [ref, setRef] = useState("");
  const [uploaded, setUploaded] = useState(false);

  const valid = ref.trim() !== "" && uploaded;

  const send = () => {
    submitPartnerPayment(id, "transfer", ref);
    navigate("bizPartnerPayResult", { flow: "pending", partnerId: id });
  };

  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-secondary-50 border border-secondary-200 p-4 flex items-start gap-2.5">
          <i className="ri-information-line text-[17px] text-secondary-900 leading-none mt-0.5" />
          <p className="text-[11.5px] text-foreground-700 leading-relaxed">
            قيمة الشراكة تتجاوز الحد المحدد، يرجى التحويل إلى حساب المنصة البنكي ثم رفع إثبات التحويل.
          </p>
        </div>

        {/* Platform bank details */}
        <div className="rounded-[20px] bg-background-100 border border-background-200 p-4">
          <h2 className="text-[14px] font-semibold text-foreground-950 mb-3">حساب المنصة البنكي</h2>
          <div className="space-y-2.5">
            <div className="flex items-center justify-between gap-3">
              <span className="text-[12px] text-foreground-600">البنك</span>
              <span className="text-[12.5px] font-semibold text-foreground-950">{PLATFORM.bank}</span>
            </div>
            <div className="flex items-center justify-between gap-3">
              <span className="text-[12px] text-foreground-600">اسم الحساب</span>
              <span className="text-[12.5px] font-semibold text-foreground-950">{PLATFORM.name}</span>
            </div>
            <div className="flex items-center justify-between gap-3">
              <span className="text-[12px] text-foreground-600">الآيبان</span>
              <span className="text-[12.5px] font-semibold text-foreground-950" dir="ltr">
                {PLATFORM.iban}
              </span>
            </div>
            <div className="flex items-center justify-between gap-3">
              <span className="text-[12px] text-foreground-600">المستفيد</span>
              <span className="text-[12.5px] font-semibold text-foreground-950">
                {row?.partnerName ?? bizPartnershipSides.partner.name}
              </span>
            </div>
          </div>
        </div>

        <Field label="الرقم المرجعي للتحويل" required>
          <TextInput value={ref} onChange={setRef} placeholder="مثال: 458812" dir="ltr" />
        </Field>

        <UploadBox
          label="رفع صورة إثبات التحويل"
          hint="صورة واضحة لإشعار التحويل البنكي"
          icon="ri-file-image-line"
          filled={uploaded}
          onToggle={() => setUploaded((v) => !v)}
        />
      </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={send}>
          إرسال الإثبات
        </Btn>
      </div>
    </div>
  );
}