import React, { Suspense } from 'react';
// import { unstable_setRequestLocale } from 'next-intl/server';
import { notFound } from 'next/navigation';
import { AccountMenu, RoomDetails, RoomsTabs } from '../../../../../../components/Account';
import { RoomsType } from '../../../../../../types/rooms';

const ROOMS_ROUTES = [RoomsType.UPCOMING, RoomsType.RECENT, RoomsType.NEW];

export async function generateStaticParams({
   params: { locale },
}: { params: { locale: string } }) {
    return [{ locale, slug: [RoomsType.UPCOMING] }];
}

export default function RoomsDetailItem({ params: { locale, slug } }: { params: { locale: string, slug?: string[] } }) {
    // unstable_setRequestLocale(locale);
    const roomType: string = slug?.length > 0 && slug[0] || '';
    const roomId: number | null = slug?.length > 1 && Number(slug[1]) || null;

    if (!slug?.length || slug?.length > 2) {
        notFound();
    }

    if (ROOMS_ROUTES.includes(roomType as RoomsType) && Number.isInteger(roomId)) {
        return (
            <Suspense fallback={<p>Loading...</p>}>
                <RoomDetails
                    locale={locale}
                    roomId={roomId || 0}
                    activeType={roomType as RoomsType}
                />
            </Suspense>
        );
    }

    if (ROOMS_ROUTES.includes(roomType as RoomsType)  && !Number.isInteger(roomId)) {
        return (
            <>
                <div className="col-xl-3 col-lg-4 d-none d-lg-block">
                    <AccountMenu locale={locale}/>
                </div>
                <div className="col-xl-9 col-lg-8 ">
                    <div className="page-account__inner">
                        <Suspense fallback={<p>Loading...</p>}>
                            <RoomsTabs
                                locale={locale}
                                activeTab={roomType as RoomsType}
                            />
                        </Suspense>
                    </div>
                </div>
            </>
        );
    }

    return notFound();
};
