<?php
/**
 * Template: templates/email/new-release-broadcast.php
 *
 * New Release Broadcast Email Body -- F-026-7
 *
 * Minimal HTML email: cover image, title, author, teaser, buy-links CTA.
 * Captured with ob_start() by MBS_ESP_Broadcast to produce the HTML body.
 *
 * Variables injected:
 *   $post_id      int     Book post ID.
 *   $book_title   string  Book title.
 *   $author_names string  Comma-separated author names.
 *   $teaser       string  Book teaser / description.
 *   $cover_url    string  Cover image URL (may be empty).
 *   $buy_links    array   Buy link rows (objects with url, retailer_key).
 *
 * @package MyBookShowroom
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo esc_html( $book_title ); ?></title>
<style>
  body { margin:0; padding:0; font-family:Georgia,serif; background:#f9f7f4; color:#2c2c2c; }
  .mbs-email-wrap { max-width:600px; margin:0 auto; background:#ffffff; }
  .mbs-email-header { background:#2C3E6B; padding:24px 32px; }
  .mbs-email-header h1 { margin:0; font-size:13px; color:#ffffff; font-family:Arial,sans-serif; letter-spacing:0.1em; text-transform:uppercase; }
  .mbs-email-body { padding:32px; }
  .mbs-email-cover { display:block; max-width:180px; height:auto; margin:0 auto 24px; border-radius:4px; }
  .mbs-email-title { font-size:28px; font-weight:bold; margin:0 0 6px; text-align:center; color:#1a1a2e; }
  .mbs-email-author { font-size:15px; margin:0 0 20px; text-align:center; color:#5a6472; }
  .mbs-email-divider { border:none; border-top:1px solid #e0d8c8; margin:20px 0; }
  .mbs-email-teaser { font-size:15px; line-height:1.65; margin:0 0 24px; }
  .mbs-email-cta-wrap { text-align:center; margin:28px 0; }
  .mbs-email-cta { display:inline-block; background:#2C3E6B; color:#ffffff; padding:12px 28px; border-radius:4px; text-decoration:none; font-family:Arial,sans-serif; font-size:15px; font-weight:bold; }
  .mbs-email-links { margin:16px 0 0; font-size:13px; text-align:center; color:#5a6472; }
  .mbs-email-links a { color:#4AABB8; text-decoration:none; margin:0 8px; }
  .mbs-email-footer { background:#f4f0e8; padding:16px 32px; font-family:Arial,sans-serif; font-size:11px; color:#888; text-align:center; }
</style>
</head>
<body>
<div class="mbs-email-wrap">
  <div class="mbs-email-header">
    <h1><?php esc_html_e( 'New Release', 'my-book-showroom' ); ?></h1>
  </div>
  <div class="mbs-email-body">
  <?php if ( ! empty( $cover_url ) ) : ?>
    <img class="mbs-email-cover" src="<?php echo esc_url( $cover_url ); ?>" alt="<?php echo esc_attr( $book_title ); ?>" />
  <?php endif; ?>
    <h2 class="mbs-email-title"><?php echo esc_html( $book_title ); ?></h2>
  <?php if ( ! empty( $author_names ) ) : ?>
    <p class="mbs-email-author"><?php echo esc_html( $author_names ); ?></p>
  <?php endif; ?>
    <hr class="mbs-email-divider" />
  <?php if ( ! empty( $teaser ) ) : ?>
    <p class="mbs-email-teaser"><?php echo wp_kses_post( $teaser ); ?></p>
  <?php endif; ?>
  <?php
  $first_link = ! empty( $buy_links ) ? reset( $buy_links ) : null; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- template-scope variable; not a global
  if ( $first_link && ! empty( $first_link->url ) ) :
  ?>
    <div class="mbs-email-cta-wrap">
      <a class="mbs-email-cta" href="<?php echo esc_url( $first_link->url ); ?>"><?php esc_html_e( 'Get Your Copy', 'my-book-showroom' ); ?></a>
    </div>
  <?php if ( count( $buy_links ) > 1 ) : ?>
    <p class="mbs-email-links">
      <?php esc_html_e( 'Also available at:', 'my-book-showroom' ); ?>
      <?php foreach ( array_slice( $buy_links, 1 ) as $link ) : ?>
        <a href="<?php echo esc_url( $link->url ); ?>"><?php echo esc_html( $link->retailer_key ?? $link->url ); ?></a>
      <?php endforeach; ?>
    </p>
  <?php endif; ?>
  <?php endif; ?>
  </div>
  <div class="mbs-email-footer">
    <p><?php esc_html_e( 'You are receiving this because you subscribed to author updates.', 'my-book-showroom' ); ?></p>
  </div>
</div>
</body>
</html>
