<?php
require_once __DIR__ . '/lib/i18n_mailer.php';

// Example: coming from your DB/user profile
$lang = $user['lang'] ?? 'en'; // 'es', 'pt', 'zh', 'ta', 'th'
$receivedDate = date('Y-m-d');
$noticeDays = 14;

// Calculate effective date (14 days after receipt)
$effectiveDate = date('Y-m-d', strtotime("+{$noticeDays} days"));

$email = build_localized_email($lang, 'cancellation', [
    'member_name'   => $user['name'] ?? '',
    'notice_days'   => $noticeDays,
    'received_date' => $receivedDate,
    'effective_date'=> $effectiveDate,
    'support_email' => 'support@yourdomain.com',
    'website_url'   => 'https://yourdomain.com'
], __DIR__);

// Send (plain text)
$to = $user['email'];
$subject = $email['subject'];
$body = $email['body'];

$headers = "From: Aloha FLY Intl. <support@yourdomain.com>\r\n";
$headers .= "Content-Type: text/plain; charset=UTF-8\r\n";

mail($to, $subject, $body, $headers);
