"use client";

import { useRouter, useParams } from "@/i18n/routing";
import UserForm from "@/components/form/user/user-form";

export default function EditUserPage() {
  const router = useRouter();
  const params = useParams();
  const userId = params?.id ? Number(params.id) : undefined;

  const handleSuccess = () => {
    router.push("/admin/management-user");
  };

  const handleCancel = () => {
    router.push("/admin/management-user");
  };

  if (!userId) {
    return (
      <div className="container mx-auto py-6">
        <div className="text-center">
          <p className="text-red-500">User ID tidak valid</p>
          <button 
            onClick={() => router.push("/admin/management-user")}
            className="mt-4 px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600"
          >
            Kembali ke Management User
          </button>
        </div>
      </div>
    );
  }

  return (
    <div className="container mx-auto py-6">
      <UserForm
        id={userId}
        mode="edit"
        onSuccess={handleSuccess}
        onCancel={handleCancel}
      />
    </div>
  );
}