# app/modules/customers/routes/pages/vendor.py
"""
Customers Vendor Page Routes (HTML rendering).

Vendor pages for customer management:
- Customers list
"""

from fastapi import APIRouter, Depends, Path, Request
from fastapi.responses import HTMLResponse
from sqlalchemy.orm import Session

from app.api.deps import get_current_vendor_from_cookie_or_header, get_db
from app.modules.core.utils.page_context import get_vendor_context
from app.templates_config import templates
from app.modules.tenancy.models import User

router = APIRouter()


# ============================================================================
# CUSTOMER MANAGEMENT
# ============================================================================


@router.get(
    "/{vendor_code}/customers", response_class=HTMLResponse, include_in_schema=False
)
async def vendor_customers_page(
    request: Request,
    vendor_code: str = Path(..., description="Vendor code"),
    current_user: User = Depends(get_current_vendor_from_cookie_or_header),
    db: Session = Depends(get_db),
):
    """
    Render customers management page.
    JavaScript loads customer list via API.
    """
    return templates.TemplateResponse(
        "customers/vendor/customers.html",
        get_vendor_context(request, db, current_user, vendor_code),
    )
