// // app/(defaults)/manage-brands/page.tsx
// import { Metadata } from 'next';
// import { getAccessToken } from '@/utils/apiHelper';
// import BrandsClient from './BrandsClient';

// export const metadata: Metadata = {
//     title: 'Brands Admin',
// };

// type Brand = {
//     id: string;
//     name: string;
//     logo?: string;
//     dropship: boolean;
// };

// async function fetchBrands(accessToken: string): Promise<Brand[]> {
//     const resp = await fetch('https://turn14.data4autos.com/v1/brands', {
//         headers: { Authorization: `Bearer ${accessToken}` },
//         cache: 'no-store',
//     });

//     if (!resp.ok) {
//         throw new Error(`Failed to fetch brands: ${resp.statusText}`);
//     }

//     const data = await resp.json();
//     return data.data || [];
// }

// export default async function BrandsPage() {
//     try {
//         const accessToken = await getAccessToken();
//         const brands = accessToken ? await fetchBrands(accessToken) : [];

//         return <BrandsClient brands={brands} />;
//     } catch (error) {
//         console.error('Error loading brands:', error);
//         // You might want to handle this error more gracefully in your application
//         return (
//             <div>
//             <div className="min-h-screen flex items-center justify-center bg-gray-100">
//                 <div className="bg-white p-8 rounded-xl shadow-md max-w-md w-full text-center">
//                     <h2 className="text-2xl font-bold text-red-600 mb-4">Error Loading Brands</h2>
//                     <p className="text-gray-600 mb-6">We encountered a problem while loading the brands. Please try again later.</p>
//                     <button onClick={() => window.location.reload()} className="px-6 py-3 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors">
//                         Try Again
//                     </button>
//                 </div>
//             </div>
//             </div>
//         );
//     }
// }
// app/(defaults)/manage-brands/page.tsx
import { Metadata } from 'next';
import { getAccessToken } from '@/utils/apiHelper';
import BrandsClient from './BrandsClient';

export const metadata: Metadata = {
  title: 'Brands Admin',
};


export default async function BrandsPage() {
  try {
    console.log()
    const accessToken = await getAccessToken();
    console.log('Access Token:', accessToken); // Debugging line
    

    return <BrandsClient  />;
  } catch (error) {
    console.error('Error loading brands:', error);
    return (
      <div className="p-8 flex items-center justify-center">
        <div className="bg-white p-8 rounded-xl shadow-md max-w-md w-full text-center">
          <h2 className="text-2xl font-bold text-red-600 mb-4">Error Loading Brands</h2>
          <p className="text-gray-600 mb-6">We encountered a problem while loading the brands. Please try again later.</p>
          <button
            onClick={() => window.location.reload()}
            className="px-6 py-3 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors"
          >
            Try Again
          </button>
        </div>
      </div>
    );
  }
}