import {
  Body,
  Head,
  Html,
  Preview,
  Tailwind,
  Text,
  render,
} from '@react-email/components';

import { BodyStyle } from '../components/body-style';
import { EmailContent } from '../components/content';
import { EmailHeader } from '../components/header';
import { EmailHeading } from '../components/heading';
import { EmailWrapper } from '../components/wrapper';

export async function renderBookTimeFailedEmail({
  reservationId,
  error,
}: {
  reservationId: number;
  error: string;
}) {
  const subject = 'Aja broneerimine ei õnnestunud';

  const html = await render(
    <Html>
      <Head>
        <BodyStyle />
      </Head>

      <Preview>{subject}</Preview>

      <Tailwind>
        <Body>
          <EmailWrapper>
            <EmailContent>
              <EmailHeader>
                <EmailHeading>{subject}</EmailHeading>
              </EmailHeader>
              <Text className="text-[16px] leading-[24px] text-[#242424]">
                Tere
              </Text>

              <Text>
                Broneeringu {reservationId} Connected Online'i saatmine ei
                õnnestunud, kliendile tuleb teha tagasimakse.
              </Text>
              <Text>Saadud error: {error}</Text>
            </EmailContent>
          </EmailWrapper>
        </Body>
      </Tailwind>
    </Html>,
  );

  return {
    html,
    subject,
  };
}
