"""HTML builders for Clarke frontend screens.""" from __future__ import annotations from datetime import date from html import escape from typing import Any def _open_patient_click_js(index: int) -> str: """Return debug-friendly JS snippet for dashboard patient button clicks. Args: index (int): Dashboard patient-card index. Returns: str: Inline JS IIFE for HTML onclick attributes. """ return ( "(function(){" f"var el=document.getElementById('hidden-select-{index}');" "if(!el){return;}" "if(el.tagName==='BUTTON'){el.click();}else{" "var btn=el.querySelector('button');" "if(btn){btn.click();}" "}" "})()" ) def build_global_style_block() -> str: """Return the global CSS block injected via gr.HTML. Args: None: This function has no runtime inputs. Returns: str: Complete style tag with animation keyframes and resets. """ return """ """ def build_dashboard_html(clinic_payload: dict[str, Any], completed_patients: list[int] | None = None) -> str: """Render the S1 dashboard markup with top gradient and white card area. Args: clinic_payload (dict[str, Any]): Clinic roster and clinician metadata. Returns: str: Complete HTML markup for the dashboard screen. """ clinician = clinic_payload.get("clinician", {}) _today = date.today().strftime("%d %B %Y") completed_lookup = set(completed_patients or []) cards: list[str] = [] for index, patient in enumerate(clinic_payload.get("patients", [])): click_js = _open_patient_click_js(index) completed = index in completed_lookup card_style = "opacity:0.55;" if completed else "" hover_class = "completed-patient-card" if completed else "" badge = "