import { use } from 'react';

import { AppBreadcrumbs } from '@kit/ui/makerkit/app-breadcrumbs';
import { PageBody } from '@kit/ui/page';
import { Trans } from '@kit/ui/trans';

import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
import { withI18n } from '~/lib/i18n/with-i18n';

import { HomeLayoutPageHeader } from '../../_components/home-page-header';
import OrderCards from '../../_components/order-cards';
import ServiceCategories from '../../_components/service-categories';
import { loadTtoServices } from '../../_lib/server/load-tto-services';

export const generateMetadata = async () => {
  const i18n = await createI18nServerInstance();
  const title = i18n.t('booking:title');

  return {
    title,
  };
};

function BookingPage() {
  const { heroCategories, ttoCategories } = use(loadTtoServices());

  if (!heroCategories.length && !ttoCategories.length) {
    return (
      <>
        <AppBreadcrumbs />
        <h3 className="mt-8">
          <Trans i18nKey="booking:noCategories" />
        </h3>
      </>
    );
  }

  return (
    <>
      <AppBreadcrumbs />
      <HomeLayoutPageHeader
        title={<Trans i18nKey={'booking:title'} />}
        description={<Trans i18nKey={'booking:description'} />}
      />

      <PageBody className="space-y-2">
        <OrderCards heroCategories={heroCategories} />
        <ServiceCategories categories={ttoCategories} />
      </PageBody>
    </>
  );
}

export default withI18n(BookingPage);
