import {
  Body,
  Button,
  Container,
  Head,
  Heading,
  Hr,
  Html,
  Img,
  Link,
  Preview,
  Section,
  Text,
  render,
} from "@react-email/components";
import * as React from "react";
interface LinearLoginCodeEmailProps {
  validationCode?: string;
  showJoinButton?: boolean;
  buttonText?: string;
  inviteLink?: string;
  logoURL?: string;
  inviteFromLocation?: string;
  inviteFromIp?: string;
  supportEmail?: string;
}
export const LinearLoginCodeEmail = ({
  validationCode,
  showJoinButton,
  buttonText,
  inviteLink,
  logoURL,
  inviteFromIp,
  inviteFromLocation,
  supportEmail,
}: LinearLoginCodeEmailProps) => (
  <Html>
    <Head />
    <Preview>Your login code for Linear</Preview>
    <Body style={main}>
      <Container style={container}>
        <Img
          src={`${logoURL}`}
          width="42"
          height="42"
          alt="Linear"
          style={logo}
        />
        <Heading style={secondary}>Your login code for Linear</Heading>
        <Section style={buttonContainer}>
          {showJoinButton && (
            <Section className="text-center mt-[32px] mb-[32px]">
              <Button style={button} href={inviteLink}>
                {buttonText}
              </Button>
            </Section>
          )}
        </Section>
        <Text style={paragraph}>
          This link and code will only be valid for the next 5 minutes. If the
          link does not work, you can use the login verification code directly:
        </Text>
        <Section style={codeContainer}>
          <Text style={code}>{validationCode}110658</Text>
        </Section>
        <Hr style={hr} />
        <Text style={paragraphSupport}>Not expecting this email?</Text>
        <Text style={paragraphSupport}>
          This invite was sent from{" "}
          <span style={paragraphSupportText}>{inviteFromIp}</span> located in{" "}
          <span style={paragraphSupportText}>{inviteFromLocation}</span>.
        </Text>
        <Text style={paragraphSupport}>
          Please contact{" "}
          <Link href="mailto:suport@linear.com" style={link}>
            {supportEmail}
          </Link>{" "}
          if you did not request this code.
        </Text>
      </Container>
    </Body>
  </Html>
);
LinearLoginCodeEmail.PreviewProps = {
  validationCode: "tt226-5398x",
} as LinearLoginCodeEmailProps;
export default LinearLoginCodeEmail;
const logo = {
  borderRadius: 21,
  width: 42,
  height: 42,
};
const main = {
  backgroundColor: "#ffffff",
  fontFamily:
    '-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif',
};
const container = {
  margin: "0 auto",
  padding: "20px 0 48px",
  maxWidth: "560px",
};
const secondary = {
  color: "#000",
  display: "inline-block",
  fontFamily: "HelveticaNeue-Medium,Helvetica,Arial,sans-serif",
  fontSize: "20px",
  fontWeight: 500,
  lineHeight: "24px",
  marginBottom: "0",
  marginTop: "2rem",
  textAlign: "center" as const,
};
const paragraphSupportText = {
  fontSize: "15px",
  fontWeight: "700",
};
const paragraph = {
  margin: "0 0 15px",
  fontSize: "15px",
  lineHeight: "1.4",
  color: "#3c4149",
};
const buttonContainer = {
  padding: "27px 0 27px",
};
const button = {
  backgroundColor: "#5e6ad2",
  borderRadius: "3px",
  fontWeight: "600",
  color: "#fff",
  fontSize: "15px",
  textDecoration: "none",
  textAlign: "center" as const,
  display: "block",
  padding: "11px 23px",
};
const hr = {
  borderColor: "#dfe1e4",
  margin: "42px 0 26px",
};
const code = {
  color: "#000",
  display: "inline-block",
  fontFamily: "HelveticaNeue-Bold",
  fontSize: "16px",
  fontWeight: 700,
  letterSpacing: "6px",
  lineHeight: "40px",
  paddingBottom: "8px",
  paddingTop: "8px",
  margin: "0 auto",
  width: "100%",
  textAlign: "center" as const,
};
const paragraphSupport = {
  color: "#444",
  fontSize: "15px",
  fontFamily: "HelveticaNeue,Helvetica,Arial,sans-serif",
  letterSpacing: "0",
  lineHeight: "23px",
  padding: "0 40px",
  margin: "0",
  textAlign: "center" as const,
};
const link = {
  color: "#444",
  textDecoration: "underline",
};
const codeContainer = {
  background: "rgba(0,0,0,.05)",
  borderRadius: "4px",
  margin: "16px auto 14px",
  verticalAlign: "middle",
  width: "280px",
};
export function renderOTPEmail(payload: any) {
  return render(<LinearLoginCodeEmail {...payload} />);
}