from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]


def read(path: str) -> str:
    return (ROOT / path).read_text(encoding="utf-8")


def test_v488_operations_returns_to_classic_card_list_layout():
    operations = read("app/admin_ui/pages/operations.py")
    styles = read("app/admin_ui/styles.py")

    assert 'id="operations-work-items" class="cf-live-panel"' in operations
    assert 'cf-work-card' in operations
    assert 'cf-work-section-title' in operations
    assert 'cf-work-section' in operations
    assert 'cf-workbench-layout' not in operations
    assert 'operations-detail-panel' not in operations
    assert '@router.get("/operations/partials/item-detail"' not in operations

    assert 'grid-template-columns:minmax(360px,440px) minmax(0,1fr)' not in styles
    assert '.cf-work-detail-panel{position:sticky' not in styles
    assert '.cf-work-row{' not in styles


def test_v488_operations_keeps_simplified_cards_without_inline_details():
    operations = read("app/admin_ui/pages/operations.py")

    assert 'operation_card_title(item)' in operations
    assert 'operation_card_subtitle(item)' in operations
    assert 'operation_has_useful_details(item)' not in operations
    assert 'Cliente fiscal' not in operations.split('def _render_work_item', 1)[1].split('details_html = ""', 1)[0]
    assert '<summary>Ver detalhes</summary>' not in operations
    assert 'operation_origin_label(item)' not in operations


def test_v488_operations_keeps_htmx_filter_partial_only():
    operations = read("app/admin_ui/pages/operations.py")

    assert '@router.get("/operations/partials/work-items"' in operations
    assert 'hx-target="#operations-work-items"' in operations
    assert 'hx-swap="outerHTML"' in operations
    assert 'hx-push-url' in operations


def test_v488_documentation_states_classic_cards_replaced_workbench():
    doc = read("docs/CLIENTFLOW_V488_OPERATIONS_CLASSIC_CARDS.md")
    assert "Operations Classic Cards" in doc
    assert "sem painel lateral fixo" in doc
    assert "Não requer migração de base de dados" in doc
    assert "Não altera regras de negócio" in doc
