// components/RegisterClient.tsx

"use client";

import Image from "next/image";
import { useSearchParams, useRouter } from "next/navigation";
import { useState } from "react";
import { useAppDispatch } from "@/store/hooks";
import { register } from "@/features/auth/authSlice";
import Navbar from "@/components/common/Navbar";

export default function RegisterPage({
  phone,
  redirect,
  order_id,
}: {
  phone: string;
  redirect: string;
  order_id: string;
}) {

  const router = useRouter();
  const dispatch = useAppDispatch();
  const [vehicle, setVehicle] = useState<"bike" | "car">("bike");

  const [form, setForm] = useState({
    full_name: "",
    email: "",
    dl_origin: "Indian",
    nationality: "Indian",
  });

  const handleRegister = async () => {
    await dispatch(
      register({
        phone_number: phone,
        alternate_phone_number: phone,
        ...form,
      })
    );

    router.push(
  `/verify-otp?phone=${phone}&redirect=${encodeURIComponent(
    redirect || "/"
  )}&order_id=${order_id || ""}`
);
  };

return (
  <>
    {/* ✅ Navbar */}
    {/* <Navbar vehicle={vehicle} setVehicle={setVehicle} /> */}

    {/* ✅ Page Content */}
    <div className="bg-[#ffffff] px-4 pt-6">
      <div className="max-w-6xl mx-auto flex items-center justify-center min-h-[calc(100vh-80px)]">

        <div className="w-full flex rounded-2xl overflow-hidden">

          {/* LEFT */}
          <div className="w-full md:w-1/2 p-8 md:p-12 flex flex-col justify-center">

            {/* Heading */}
            <h2 className="text-3xl md:text-4xl font-bold text-[#2D2D2D] mb-4">
              Complete Profile 📝
            </h2>

            <p className="text-gray-500 mb-6 text-sm">
              Just a few details to get started
            </p>

            {/* NAME */}
            <input
              placeholder="Full Name"
              className="w-full bg-gray-100 px-4 py-3 rounded-lg mb-3 outline-none"
              onChange={(e) =>
                setForm({ ...form, full_name: e.target.value })
              }
            />

            {/* EMAIL */}
            <input
              placeholder="Email"
              className="w-full bg-gray-100 px-4 py-3 rounded-lg mb-4 outline-none"
              onChange={(e) =>
                setForm({ ...form, email: e.target.value })
              }
            />

            {/* BUTTON */}
            <button
              onClick={handleRegister}
              className="w-full bg-primary text-white py-3 rounded-lg font-medium hover:opacity-90"
            >
              Register & Send OTP
            </button>
          </div>

          {/* RIGHT IMAGE */}
          <div className="hidden md:flex w-1/2 items-center justify-center p-6">
            <div className="relative w-[420px] h-[520px]">
              <Image
                src="/auth-bike.webp"
                alt="Bike"
                fill
                className="object-cover rounded-2xl"
              />
            </div>
          </div>

        </div>
      </div>
    </div>
  </>
);
}