/*
 * Copyright 2026 Palantir Technologies, Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import classnames from "classnames";
import React, { useMemo } from "react";
import styles from "./BaseEmailViewer.module.css";
function formatAddress(address) {
  if (address.name) {
    return `${address.name} <${address.address}>`;
  }
  return address.address;
}
function formatAddressList(addresses) {
  return addresses.map(formatAddress).join(", ");
}
export function BaseEmailViewer({
  email,
  className
}) {
  const rootClassName = classnames(styles.container, className);
  const bodyContent = useMemo(() => {
    if (email.html != null) {
      return /*#__PURE__*/React.createElement("div", {
        className: styles.bodyContainer
      }, /*#__PURE__*/React.createElement("iframe", {
        className: styles.bodyIframe,
        sandbox: "allow-same-origin",
        srcDoc: email.html,
        title: "Email body"
      }));
    }
    if (email.text != null) {
      return /*#__PURE__*/React.createElement("div", {
        className: styles.textBody
      }, email.text);
    }
    return /*#__PURE__*/React.createElement("div", {
      className: styles.emptyBody
    }, "No content");
  }, [email.html, email.text]);
  return /*#__PURE__*/React.createElement("div", {
    className: rootClassName
  }, /*#__PURE__*/React.createElement("div", {
    className: styles.header
  }, email.subject != null && /*#__PURE__*/React.createElement("div", {
    className: styles.subject
  }, email.subject), email.from != null && /*#__PURE__*/React.createElement("div", {
    className: styles.headerRow
  }, /*#__PURE__*/React.createElement("span", {
    className: styles.headerLabel
  }, "From:"), /*#__PURE__*/React.createElement("span", {
    className: styles.headerValue
  }, formatAddress(email.from))), email.to.length > 0 && /*#__PURE__*/React.createElement("div", {
    className: styles.headerRow
  }, /*#__PURE__*/React.createElement("span", {
    className: styles.headerLabel
  }, "To:"), /*#__PURE__*/React.createElement("span", {
    className: styles.headerValue
  }, formatAddressList(email.to))), email.cc.length > 0 && /*#__PURE__*/React.createElement("div", {
    className: styles.headerRow
  }, /*#__PURE__*/React.createElement("span", {
    className: styles.headerLabel
  }, "Cc:"), /*#__PURE__*/React.createElement("span", {
    className: styles.headerValue
  }, formatAddressList(email.cc))), email.date != null && /*#__PURE__*/React.createElement("div", {
    className: styles.headerRow
  }, /*#__PURE__*/React.createElement("span", {
    className: styles.headerLabel
  }, "Date:"), /*#__PURE__*/React.createElement("span", {
    className: styles.headerValue
  }, email.date))), bodyContent);
}
//# sourceMappingURL=BaseEmailViewer.js.map