import asyncio
import json
import sys
from simulate_all import PureVectorEmbedder, qdrant_score
from inspect_mem0 import inspect_live_mem0

if hasattr(sys.stdout, "reconfigure"):
    sys.stdout.reconfigure(encoding="utf-8", errors="replace")

async def test_frontend():
    dscons_mems, non_dscons_mems = await inspect_live_mem0()
    embedder = PureVectorEmbedder()
    
    embedded_non_dscons = []
    for m in non_dscons_mems:
        v = embedder.embed(m.get("memory", ""))
        embedded_non_dscons.append((m, v))
        
    text_boost_f01 = r"""[DSCons Frontend Theme: Dark Slate Design System & Palette | Frontend Theme & Color Palette | Bảng Màu Giao Diện ERP Frontend Theme] Giao diện frontend theme DSCons ERP áp dụng chuẩn thiết kế Enterprise Dark Slate Theme: Màu nền chính #0b0f19 / #080d1a, thẻ/panel #111827, đường viền #1e293b. Bảng màu (color palette) frontend theme chuẩn dark slate. Mọi màn hình bắt buộc import stylesheet dùng chung /static/css/erp_enterprise.css và thanh điều hướng thống nhất <header class="erp-navbar"> với logo DSCons, menu phân hệ và trạng thái tài khoản."""
    text_boost_f02 = r"""[DSCons Frontend Theme: Typography Standards & Font Hierarchy | Frontend Theme Fonts Inter & JetBrains Mono] Giao diện frontend theme DSCons chuẩn hóa kiểu chữ: Google Fonts Inter hỗ trợ đầy đủ tiếng Việt cho toàn bộ tiêu đề và nội dung; Font JetBrains Mono cho toàn bộ số liệu tài chính VNĐ, đơn giá ca máy, mã thiết bị, và tọa độ CAD. Phân cấp cỡ chữ chặt chẽ: Tiêu đề trang 15px-17px (bold), Thẻ 13px-14px, Nội dung 12px-13px, Nhãn phụ Meta 10.5px-11.5px uppercase tracking."""
    text_boost_f03 = r"""[DSCons Frontend Theme: High-Density Bloomberg Layout & Zero Sidebar Occlusion | Frontend Theme Layout Density] Frontend theme DSCons tối ưu mật độ thông tin cao (Bloomberg/Palantir density): Paddings/gaps gọn gàng 8px-14px cho cards và 6px-10px cho hàng dữ liệu, chia cột Multi-Column Split-View. Chống đè menu (Zero Occlusion): Toàn bộ bố cục chính .erp-main-layout bao bọc nội dung với margin-left: var(--sidebar-width) (260px desktop, 72px collapsed), cấm để sidebar cố định che khuất nội dung."""

    f01_v = embedder.embed(text_boost_f01)
    f02_v = embedder.embed(text_boost_f02)
    f03_v = embedder.embed(text_boost_f03)

    for q in ["frontend theme", "bảng màu frontend", "frontend color palette"]:
        qv = embedder.embed(q)
        s_f01 = qdrant_score(qv, f01_v)
        s_f02 = qdrant_score(qv, f02_v)
        s_f03 = qdrant_score(qv, f03_v)
        
        scored = [(qdrant_score(qv, mv), m.get("id"), m.get("memory", "")[:60]) for m, mv in embedded_non_dscons]
        scored.sort(key=lambda x: x[0], reverse=True)
        print(f"\n--- Query: '{q}' ---")
        print(f"F01: {s_f01:.4f} | F02: {s_f02:.4f} | F03: {s_f03:.4f}")
        print(f"Top non-dscons #1: {scored[0][0]:.4f} ({scored[0][2]})")
        print(f"Top non-dscons #2: {scored[1][0]:.4f} ({scored[1][2]})")

if __name__ == "__main__":
    asyncio.run(test_frontend())
