import { useApp } from "@/pages/app/AppContext";
import { useProductStore } from "@/pages/product/store";
import { Btn, LogoMark } from "@/pages/app/components/ui";
import BizSignupTrack from "@/pages/app/components/biz/BizSignupTrack";

/** Rejection notice shown when the admin declines the owner's registration (section 2.1). */
export default function BizRejected() {
  const { jump } = useApp();
  const { bizSignup, restartBizSignup } = useProductStore();
  const hasSignup = bizSignup.status === "rejected";

  const resubmit = () => {
    restartBizSignup();
    jump("bizRegister");
  };

  return (
    <div className="min-h-full flex flex-col bg-background-50">
      <div className="px-5 pt-6 pb-3 flex items-center justify-center">
        <div className="w-12 h-12 rounded-[14px] bg-primary-500 flex items-center justify-center">
          <LogoMark className="text-[17px] text-background-50" />
        </div>
      </div>

      <div className="flex-1 px-5 pb-6">
        <div className="flex flex-col items-center text-center">
          <div className="w-24 h-24 rounded-full bg-danger-50 flex items-center justify-center mb-5">
            <i className="ri-close-line text-[50px] text-danger-500 leading-none" />
          </div>
          <h1 className="text-[21px] font-bold text-foreground-950">لم يتم اعتماد حسابك</h1>
          <p className="text-[13px] text-foreground-600 mt-3 leading-relaxed max-w-[310px]">
            {hasSignup
              ? "راجع سبب الرفض أدناه، عدّل بيانات منشأتك ثم أعد إرسال الطلب. بياناتك السابقة محفوظة."
              : "لا يوجد طلب مرفوض حاليًا. يمكنك بدء تسجيل منشأة جديدة في أي وقت."}
          </p>
        </div>

        {hasSignup && (
          <div className="mt-5 space-y-4">
            <BizSignupTrack status="rejected" />

            <div className="rounded-[16px] bg-danger-50 border border-danger-200 p-4 text-right">
              <p className="text-[11.5px] font-semibold text-danger-700 mb-1.5 flex items-center gap-1.5">
                <i className="ri-error-warning-line text-[14px] leading-none" />
                سبب الرفض
              </p>
              <p className="text-[12.5px] text-foreground-700 leading-relaxed">{bizSignup.rejectReason}</p>
            </div>

            <div className="rounded-[16px] bg-background-100 border border-background-200 p-4 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">{bizSignup.profile.businessName || "—"}</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-medium text-foreground-900">{bizSignup.profile.city || "—"}</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-medium text-foreground-900" dir="ltr">+966 {bizSignup.profile.phone || "—"}</span>
              </div>
            </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-lightbulb-line text-[16px] text-foreground-500 leading-none mt-0.5 shrink-0" />
              <span className="text-[11px] text-foreground-600 leading-relaxed">
                أكثر أسباب الرفض شيوعًا: اسم النشاط لا يطابق السجل التجاري، أو رقم الجوال غير صحيح، أو المدينة غير محددة.
              </span>
            </div>
          </div>
        )}
      </div>

      <div className="sticky bottom-0 z-30 px-5 py-5 bg-background-50 border-t border-background-200/70 space-y-2.5">
        <Btn full onClick={hasSignup ? resubmit : () => jump("bizRegister")}>
          {hasSignup ? "تعديل البيانات وإعادة الإرسال" : "تسجيل منشأة جديدة"}
        </Btn>
        <button
          type="button"
          onClick={() => jump("welcome")}
          className="w-full text-center text-[12.5px] font-semibold text-foreground-700 cursor-pointer"
        >
          العودة للرئيسية
        </button>
      </div>
    </div>
  );
}