<?php
/**
 * Email template: Admin payment-failed alert.
 *
 * Variables available:
 *   @var \Donatico\Models\Donation        $donation
 *   @var string                           $amount   Formatted amount with symbol.
 *   @var \Donatico\Emails\TemplateRenderer $renderer
 *
 * @package Donatico
 */

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

// Variables are set by PaymentFailedAlert::onDonationFailed() + 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 esc_html_e( 'Payment Failed', '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%;">

    <!-- Warning header -->
    <tr>
      <td style="background:#f59e0b;border-radius:8px 8px 0 0;padding:28px 32px;text-align:center;">
        <p style="margin:0 0 6px;font-size:30px;line-height:1;">⚠️</p>
        <h1 style="margin:0;color:#ffffff;font-size:20px;font-weight:700;">
          <?php esc_html_e( 'Payment Failed', 'donatico' ); ?>
        </h1>
        <p style="margin:6px 0 0;color:#fef3c7;font-size:14px;">
          <?php echo esc_html( $site_name ); ?>
        </p>
      </td>
    </tr>

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

        <p style="margin:0 0 20px;font-size:15px;color:#374151;line-height:1.6;">
          <?php
          printf(
            /* translators: 1: amount, 2: donor display name */
            esc_html__( 'A donation attempt of %1$s from %2$s did not complete successfully. No charge was made.', 'donatico' ),
            '<strong>' . esc_html( $amount ) . '</strong>',
            '<strong>' . esc_html( $donation->getDisplayName() ) . '</strong>'
          );
          ?>
        </p>

        <!-- Details -->
        <table width="100%" cellpadding="0" cellspacing="0" border="0"
               style="border:1px solid #fde68a;border-radius:6px;overflow:hidden;margin-bottom:24px;font-size:14px;">
          <tr style="background:#fffbeb;">
            <td style="padding:10px 16px;color:#92400e;font-weight:600;width:38%;border-bottom:1px solid #fde68a;">
              <?php esc_html_e( 'Attempted Amount', 'donatico' ); ?>
            </td>
            <td style="padding:10px 16px;color:#1f2937;border-bottom:1px solid #fde68a;">
              <?php echo esc_html( $amount ); ?>
            </td>
          </tr>
          <tr style="background:#ffffff;">
            <td style="padding:10px 16px;color:#92400e;font-weight:600;border-bottom:1px solid #fde68a;">
              <?php esc_html_e( 'Donor', 'donatico' ); ?>
            </td>
            <td style="padding:10px 16px;color:#1f2937;border-bottom:1px solid #fde68a;">
              <?php echo esc_html( $donation->getDisplayName() ); ?>
              <?php if ( ! $donation->isAnonymous() ) : ?>
                &lt;<a href="mailto:<?php echo esc_attr( $donation->getDonorEmail() ); ?>"
                        style="color:#f59e0b;"><?php echo esc_html( $donation->getDonorEmail() ); ?></a>&gt;
              <?php endif; ?>
            </td>
          </tr>
          <tr style="background:#fffbeb;">
            <td style="padding:10px 16px;color:#92400e;font-weight:600;border-bottom:1px solid #fde68a;">
              <?php esc_html_e( 'Time', 'donatico' ); ?>
            </td>
            <td style="padding:10px 16px;color:#1f2937;border-bottom:1px solid #fde68a;">
              <?php echo esc_html( (string) $date_label ); ?>
            </td>
          </tr>
          <tr style="background:#ffffff;">
            <td style="padding:10px 16px;color:#92400e;font-weight:600;">
              <?php esc_html_e( 'Donation ID', 'donatico' ); ?>
            </td>
            <td style="padding:10px 16px;color:#1f2937;">
              #<?php echo esc_html( (string) $donation->getId() ); ?>
            </td>
          </tr>
        </table>

        <p style="margin:0 0 20px;font-size:14px;color:#6b7280;line-height:1.6;">
          <?php esc_html_e( 'The donor may retry at any time. If the problem persists, they should contact their card issuer.', 'donatico' ); ?>
        </p>

        <!-- CTA -->
        <table width="100%" cellpadding="0" cellspacing="0" border="0">
          <tr>
            <td>
              <a href="<?php echo esc_url( $admin_url ); ?>"
                 style="display:inline-block;background:#f59e0b;color:#ffffff;text-decoration:none;font-size:14px;font-weight:700;padding:11px 24px;border-radius:6px;">
                <?php esc_html_e( 'View in 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:18px 32px;text-align:center;">
        <p style="margin:0;font-size:12px;color:#9ca3af;">
          <?php
          printf(
            /* translators: 1: plugin name and version string, 2: site name as a hyperlink */
            esc_html__( 'Sent by %1$s · %2$s', 'donatico' ),
            'Donatico v' . esc_html( DONATICO_VERSION ),
            '<a href="' . esc_url( home_url( '/' ) ) . '" style="color:#f59e0b;text-decoration:none;">' . esc_html( $site_name ) . '</a>'
          );
          ?>
        </p>
      </td>
    </tr>

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

</body>
</html>
