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

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

class EmailSummary extends React.Component<
	EmailSummaryProps,
	EmailSummaryState
> {
	componentDidMount() {
		this.ensureData();
	}
	componentDidUpdate() {
		this.ensureData();
	}

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

	render() {
		return (
			<div className="p-2" key={this.props.emailId}>
				{this.props.email != null
					? this.props.email.subject
					: this.props.emailId}
			</div>
		);
	}
}
export default EmailSummary;
