"""
Public routes: landing page and pricing page.
No login required for either route.

Each view is registered on two rules — see the blueprint docstring for why the
English one carries no language prefix.
"""

from flask import render_template, redirect, url_for, request
from flask_login import current_user

from . import public_bp


@public_bp.route("/", defaults={"lang": None})
@public_bp.route("/<lang:lang>/")
def index():
    """
    Root route.
    Authenticated users → /inbox (preserves the previous @login_required behaviour).
    Anonymous visitors → marketing landing page.

    `?preview=1` renders the landing page instead of redirecting, so the real
    front page can be reviewed while logged in without a private window.
    """
    if current_user.is_authenticated and not request.args.get("preview"):
        return redirect(url_for("dashboard"))
    return render_template("public/landing.html")


@public_bp.route("/pricing", defaults={"lang": None})
@public_bp.route("/<lang:lang>/pricing")
def pricing():
    """Standalone pricing page — accessible whether logged in or not."""
    return render_template("public/pricing.html")
