<?php
/**
 * Email template: Admin donation notification.
 *
 * Variables available (set by AdminNotification::send() + TemplateRenderer):
 *   @var \Donatico\Models\Donation $donation
 *   @var string                    $amount   Formatted amount with symbol.
 *   @var string                    $name     Donor display name.
 *   @var \Donatico\Emails\TemplateRenderer $renderer
 *
 * Merge tags in the HTML are replaced by TemplateRenderer::render() after include.
 *
 * @package Donatico
 */

if ( ! defined( 'ABSPATH' ) ) { exit; }

// Variables are set by AdminNotification::send() + TemplateRenderer::render() before include.
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound

$site_name  = get_bloginfo( 'name' );
$admin_url  = admin_url( 'admin.php?page=donatico-donations' );
$date_label = wp_date( get_option( 'date_format', 'F j, Y' ) . ' ' . get_option( 'time_format', 'g:i a' ), strtotime( $donation->getCreatedAt() ) );
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title><?php echo esc_html__( 'New Donation', 'donatico' ); ?></title>
</head>
<body style="margin:0;padding:0;background-color:#f3f4f6;font-family:Arial,Helvetica,sans-serif;-webkit-font-smoothing:antialiased;">

<table width="100%" cellpadding="0" cellspacing="0" border="0" style="background-color:#f3f4f6;">
<tr><td align="center" style="padding:40px 16px;">

  <!-- Container -->
  <table width="600" cellpadding="0" cellspacing="0" border="0" style="max-width:600px;width:100%;">

    <!-- Header -->
    <tr>
      <td style="background:#10b981;border-radius:8px 8px 0 0;padding:32px;text-align:center;">
        <p style="margin:0 0 6px;font-size:32px;line-height:1;">🎉</p>
        <h1 style="margin:0;color:#ffffff;font-size:22px;font-weight:700;letter-spacing:-.3px;">
          <?php esc_html_e( 'New Donation Received!', 'donatico' ); ?>
        </h1>
        <p style="margin:6px 0 0;color:#d1fae5;font-size:15px;">
          <?php echo esc_html( $site_name ); ?>
        </p>
      </td>
    </tr>

    <!-- Body -->
    <tr>
      <td style="background:#ffffff;padding:32px;">

        <p style="margin:0 0 24px;font-size:15px;color:#374151;line-height:1.6;">
          <?php
          printf(
            /* translators: 1: amount, 2: donor name */
            esc_html__( 'You\'ve received a new donation of %1$s from %2$s.', 'donatico' ),
            '<strong style="color:#059669;">' . esc_html( $amount ) . '</strong>',
            '<strong>' . esc_html( $name ) . '</strong>'
          );
          ?>
        </p>

        <!-- Details table -->
        <table width="100%" cellpadding="0" cellspacing="0" border="0"
               style="border:1px solid #e5e7eb;border-radius:6px;overflow:hidden;margin-bottom:28px;font-size:14px;">

          <?php
          $rows = array(
            __( 'Amount', 'donatico' )        => '<strong style="color:#059669;">' . esc_html( $amount ) . '</strong>',
            __( 'Donor Name', 'donatico' )    => esc_html( $name ),
            __( 'Donor Email', 'donatico' )   => $donation->isAnonymous() ? esc_html__( '—', 'donatico' ) : '<a href="mailto:' . esc_attr( $donation->getDonorEmail() ) . '" style="color:#10b981;">' . esc_html( $donation->getDonorEmail() ) . '</a>',
            __( 'Date', 'donatico' )          => esc_html( (string) $date_label ),
            __( 'Donation ID', 'donatico' )   => '#' . esc_html( (string) $donation->getId() ),
            __( 'Anonymous', 'donatico' )     => $donation->isAnonymous() ? esc_html__( 'Yes', 'donatico' ) : esc_html__( 'No', 'donatico' ),
          );

          if ( $donation->getStripeSessionId() ) {
            $rows[ __( 'Stripe Session', 'donatico' ) ] = '<code style="font-size:12px;color:#6b7280;">' . esc_html( $donation->getStripeSessionId() ) . '</code>';
          }

          $bg = '#ffffff';
          foreach ( $rows as $label => $value ) :
            $bg = ( $bg === '#ffffff' ) ? '#f9fafb' : '#ffffff';
          ?>
          <tr style="background:<?php echo esc_attr( $bg ); ?>;">
            <td style="padding:11px 16px;color:#6b7280;font-weight:600;width:38%;border-bottom:1px solid #e5e7eb;">
              <?php echo esc_html( $label ); ?>
            </td>
            <td style="padding:11px 16px;color:#1f2937;border-bottom:1px solid #e5e7eb;">
              <?php
              echo wp_kses(
                $value,
                array(
                  'strong' => array( 'style' => array() ),
                  'a'      => array( 'href' => array(), 'style' => array() ),
                  'code'   => array( 'style' => array() ),
                )
              );
              ?>
            </td>
          </tr>
          <?php endforeach; ?>

          <?php if ( $donation->getMessage() ) : ?>
          <tr style="background:#f9fafb;">
            <td style="padding:11px 16px;color:#6b7280;font-weight:600;vertical-align:top;">
              <?php esc_html_e( 'Message', 'donatico' ); ?>
            </td>
            <td style="padding:11px 16px;color:#1f2937;font-style:italic;">
              <?php echo esc_html( $donation->getMessage() ); ?>
            </td>
          </tr>
          <?php endif; ?>

        </table>

        <!-- CTA button -->
        <table width="100%" cellpadding="0" cellspacing="0" border="0" style="margin-bottom:8px;">
          <tr>
            <td align="center">
              <a href="<?php echo esc_url( $admin_url ); ?>"
                 style="display:inline-block;background:#10b981;color:#ffffff;text-decoration:none;font-size:15px;font-weight:700;padding:13px 28px;border-radius:6px;letter-spacing:-.1px;">
                <?php esc_html_e( 'View in Donatico Admin →', 'donatico' ); ?>
              </a>
            </td>
          </tr>
        </table>

      </td>
    </tr>

    <!-- Footer -->
    <tr>
      <td style="background:#f9fafb;border:1px solid #e5e7eb;border-radius:0 0 8px 8px;padding:20px 32px;text-align:center;">
        <p style="margin:0;font-size:12px;color:#9ca3af;">
          <?php
          printf(
            /* translators: plugin name + version */
            esc_html__( 'Sent by %1$s · %2$s', 'donatico' ),
            'Donatico v' . esc_html( DONATICO_VERSION ),
            '<a href="' . esc_url( home_url( '/' ) ) . '" style="color:#10b981;text-decoration:none;">' . esc_html( $site_name ) . '</a>'
          );
          ?>
        </p>
      </td>
    </tr>

  </table>
</td></tr>
</table>

</body>
</html>
