import React from "react";
import Placeholder from "react-bootstrap/Placeholder";

import Client from "./client/Client";
import { IAccount, IEmail } from "./client/types";

type EmailContentProps = {
	account: IAccount | null;
	client: Client | null;
	email: IEmail | null;
	emailId: string;
};

type EmailContentState = {};

class EmailContent extends React.Component<
	EmailContentProps,
	EmailContentState
> {
	componentDidMount() {
		this.ensureData();
	}
	componentDidUpdate() {
		this.ensureData();
	}

	ensureData() {
		if (this.props.account == null) return;
		if (this.props.client == null) return;
		this.props.client.ensureEmailContent(
			this.props.account.id,
			this.props.emailId,
		);
	}

	render() {
		if (this.props.email == null) {
			return <Placeholder />;
		} else {
			return <p>{this.props.email.preview}</p>;
		}
	}
}
export default EmailContent;
