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

Vendor pages for core functionality:
- Media library
- Notifications
"""

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


# ============================================================================
# MEDIA LIBRARY
# ============================================================================


@router.get(
    "/{vendor_code}/media", response_class=HTMLResponse, include_in_schema=False
)
async def vendor_media_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 media library page.
    JavaScript loads media files via API.
    """
    return templates.TemplateResponse(
        "cms/vendor/media.html",
        get_vendor_context(request, db, current_user, vendor_code),
    )


# ============================================================================
# NOTIFICATIONS
# ============================================================================


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