<?php

function renderEmailTemplate(string $name, array $vars = []): string {
    extract($vars, EXTR_SKIP);
    ob_start();
    include dirname(__DIR__) . '/email-templates/' . $name . '.php';
    return ob_get_clean();
}

function sendProjectEmails(array $session, string $pdfPath): void {
    $projectName    = !empty($session['project_num']) ? $session['project_num'] : 'Your Ramp Design';
    $niceFilename   = $projectName . ' - ' . date('F j, Y') . '.pdf';

    sendEmail(
        [$session['email'] => $session['designed_by']],
        'Your Ramp Design',
        renderEmailTemplate('customer', ['session' => $session]),
        [$pdfPath => $niceFilename]
    );

    if (empty($session['is_dealer'])) return;

    sendEmail(
        ['Sales@QRamp.com' => 'QRamp Sales'],
        'New Ramp Design from Authorized Dealer',
        renderEmailTemplate('sales', ['session' => $session]),
        [$pdfPath => $niceFilename]
    );
}
