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

Vendor pages for product management:
- Products list
- Product create
"""

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()


# ============================================================================
# PRODUCT MANAGEMENT
# ============================================================================


@router.get(
    "/{vendor_code}/products", response_class=HTMLResponse, include_in_schema=False
)
async def vendor_products_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 products management page.
    JavaScript loads product list via API.
    """
    return templates.TemplateResponse(
        "catalog/vendor/products.html",
        get_vendor_context(request, db, current_user, vendor_code),
    )


@router.get(
    "/{vendor_code}/products/create",
    response_class=HTMLResponse,
    include_in_schema=False,
)
async def vendor_product_create_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 product creation page.
    JavaScript handles form submission via API.
    """
    return templates.TemplateResponse(
        "catalog/vendor/product-create.html",
        get_vendor_context(request, db, current_user, vendor_code),
    )
