/*
  This page is for the booking confirmed.
  It includes a section with the booking details.
  It also includes a section with the booking summary.
*/
import { getDictionarys } from '@/getDictionarys';
import BookingConfirmed from '@/src/components/page/FindAHome/BookingConfirmed/BookingConfirmed';
import getProfileView, { getEncryptedCookie } from '@/src/ssrapi/getProfileView';
import { BookingConfirmedData } from '@/src/types/StaticContent/booking-confirmed.type';
import { AUTH_COOKIES } from '@/src/utils/commonVariables';
import { encryptData } from '@/src/utils/encryptionFunctions';
import { cookies } from 'next/headers';
import React from 'react';

interface SlugParams {
    params: {
        slug: string;
        bookingId: string
    };
}

const page: React.FC<SlugParams> = async ({ params }) => {
    const { slug, bookingId } = await params;

    const ProfileData = await getProfileView();
    const BookingConfirmedData = await getDictionarys('booking-confirmed') as BookingConfirmedData;

    const cookieStore = await cookies();
    const cookie = cookieStore.get(AUTH_COOKIES.USER_TOKEN)?.value;
    const authToken = cookie && getEncryptedCookie(cookie) || ''

    let encryptedValue = null
    let userType = null
    let dashboardUrl = null
    let myBookingUrl = null

    // Encrypt the data for passing to the dashboard site as query params
    if (ProfileData?.data) {
        encryptedValue = authToken && encryptData(JSON.stringify(authToken));
        userType = authToken && encryptData(JSON.stringify('guest'));
        dashboardUrl = authToken && encryptData(JSON.stringify('dashboard'));
        myBookingUrl = authToken && encryptData(JSON.stringify('my-booking'));
    }

    return (
        <BookingConfirmed
            slug={slug}
            bookingId={bookingId}
            encryptedValue={encryptedValue}
            userType={userType}
            dashboardUrl={dashboardUrl}
            myBookingUrl={myBookingUrl}
            BookingConfirmedData={BookingConfirmedData}
        />
    )
}

export default page