import AuctionClient from "@/(pages)/autionClient/AuctionClient";
import { getAuctionById } from "@/actions/auction";
import { notFound } from "next/navigation";
import Link from "next/link";

export default async function DashboardAuctionViewPage({
  params,
}: {
  params: Promise<{ lang: string; id: string }>;
}) {
  const { id, lang } = await params;

  try {
    const data = await getAuctionById(id);

    if (!data) {
      notFound();
    }

    return (
      <div dir="rtl" className="min-h-screen p-4">
        {/* Back button */}
        <div className="flex justify-end mb-4">
          <Link
            href={`/${lang}/dashboard?tab=auctions`}
            className="px-4 py-2 bg-white border border-gray-300 rounded-lg hover:bg-gray-50 transition-colors flex items-center gap-2 text-sm font-medium shadow-sm"
          >
            <span>←</span>
            <span>العودة للخلف</span>
          </Link>
        </div>

        {/* Auction details - same as public page */}
        <AuctionClient item={data} />
      </div>
    );
  } catch (error) {
    console.error("Error fetching auction:", error);
    notFound();
  }
}
