<?php
/**
 * Email template: Order Status Update — Customer.
 *
 * Sent when an order status changes to a status with notify_customer = 1.
 *
 * Available variables:
 *   $order      — Full order row (status_handle + status_label already updated)
 *   $old_handle — Previous status handle string
 *   $new_label  — Human-readable new status name
 *   $site_name  — Blog name
 *   $site_url   — Home URL
 *   $mailer     — Mailer instance
 *
 * @package TitanCart
 */
defined( 'ABSPATH' ) || exit;

$currency      = $order['currency'] ?? 'USD';
$my_orders_url = apply_filters( 'titancart_my_orders_url', home_url( '/my-orders/' ) );
$order_url     = add_query_arg( 'tc_order', $order['order_number'], $my_orders_url );
?>

<h1 style="margin-bottom:4px;"><?php esc_html_e( 'Order Update', 'titancart-lite' ); ?></h1>
<p style="color:#5A6270;font-size:13px;margin-bottom:24px;">
    <?php
    printf(
        /* translators: %s: order number */
        esc_html__( 'There is an update on your order %s.', 'titancart-lite' ),
        '<strong>' . esc_html( $order['order_number'] ) . '</strong>'
    );
    ?>
</p>

<!-- Status card -->
<div style="background:#F6F8FB;border-radius:10px;padding:20px 24px;margin-bottom:28px;text-align:center;">
    <div style="font-size:12px;color:#5A6270;margin-bottom:6px;"><?php esc_html_e( 'Order Status', 'titancart-lite' ); ?></div>
    <div style="display:inline-block;">
        <span class="status-badge" style="font-size:14px;padding:6px 16px;background:<?php echo esc_attr( $order['status_color'] ?? '#1F6AE1' ); ?>22;color:<?php echo esc_attr( $order['status_color'] ?? '#1F6AE1' ); ?>;">
            <?php echo esc_html( $new_label ); ?>
        </span>
    </div>
</div>

<!-- CTA -->
<p style="text-align:center;margin-bottom:32px;">
    <a href="<?php echo esc_url( $order_url ); ?>" class="btn">
        <?php esc_html_e( 'View Order', 'titancart-lite' ); ?>
    </a>
</p>

<hr class="divider">

<!-- Quick summary -->
<h2><?php esc_html_e( 'Order Summary', 'titancart-lite' ); ?></h2>

<p style="font-size:13px;margin-bottom:16px;">
    <strong><?php esc_html_e( 'Order:', 'titancart-lite' ); ?></strong> <?php echo esc_html( $order['order_number'] ); ?><br>
    <strong><?php esc_html_e( 'Placed:', 'titancart-lite' ); ?></strong> <?php echo esc_html( titancart_format_date( $order['created_at'] ) ); ?><br>
    <strong><?php esc_html_e( 'Total:', 'titancart-lite' ); ?></strong> <?php echo esc_html( $mailer->format_money( $order['total'], $currency ) ); ?>
</p>

<!-- Shipping address -->
<div class="address-block" style="margin-bottom:16px;">
    <strong><?php esc_html_e( 'Shipping to:', 'titancart-lite' ); ?></strong><br>
    <?php echo nl2br( esc_html( titancart_format_address( $order, 'shipping' ) ) ); ?>
</div>

<hr class="divider">
<p style="color:#5A6270;font-size:12px;text-align:center;">
    <?php
    printf(
        /* translators: %s: site name */
        esc_html__( 'Questions? Contact %s support.', 'titancart-lite' ),
        esc_html( $site_name )
    );
    ?>
</p>
