<?php

use Core\Controller;
use Core\Auth;
use Core\Pricing;

/**
 * MarketingController — the public site: homepage and pricing.
 * No auth required. Already-logged-in visitors are sent straight to their
 * dashboard instead of seeing the pitch for a product they're already in.
 */
class MarketingController extends Controller
{
    public function home(): void
    {
        if (Auth::check()) {
            $this->redirect(APP_URL . '/dashboard');
        }
        // home.php composes its own full document (ob_start + require the
        // marketing layout) — render() detects the resulting <!DOCTYPE html>
        // and echoes it as-is instead of double-wrapping.
        $this->render('marketing/home', []);
    }

    public function pricing(): void
    {
        if (Auth::check()) {
            $this->redirect(APP_URL . '/dashboard');
        }

        $currencyOverride = $this->getGet('currency', '');
        $pricing = Pricing::resolvePublicPlans($currencyOverride ?: null);

        $this->render('marketing/pricing', ['pricing' => $pricing]);
    }
}
