from __future__ import annotations

import unittest
from pathlib import Path


PROJECT_ROOT = Path(__file__).resolve().parents[1]
STATIC_ROOT = PROJECT_ROOT / "arr_web" / "static"


class DailyVisualStaticContractTests(unittest.TestCase):
    @classmethod
    def setUpClass(cls) -> None:
        cls.html = (STATIC_ROOT / "index.html").read_text(encoding="utf-8")
        cls.styles = (STATIC_ROOT / "styles.css").read_text(encoding="utf-8")

    def test_daily_workspace_uses_one_clear_history_title(self) -> None:
        self.assertIn('<span class="brand-name">ARR Report</span>', self.html)
        self.assertIn('<h2 id="daily-history-title">Daily Report</h2>', self.html)
        self.assertNotIn('<h1 class="daily-title">Daily Report</h1>', self.html)
        self.assertNotIn('class="daily-section-heading"', self.html)
        self.assertNotIn("THIS MONTH", self.html)
        self.assertNotIn("日报处理记录", self.html)
        self.assertIn("font-size: clamp(20px, 1.75vw, 24px)", self.styles)

    def test_task_log_utility_is_a_low_emphasis_link(self) -> None:
        self.assertIn('<a class="task-log-link"', self.html)
        self.assertIn("font-size: 12px", self.styles)
        self.assertIn(".task-log-link:hover", self.styles)
        self.assertIn(".task-log-link:active", self.styles)

    def test_daily_overview_places_upload_and_metrics_in_one_grid(self) -> None:
        overview_start = self.html.index('<section class="daily-overview"')
        overview_end = self.html.index('</section>\n\n        <section class="panel table-panel"', overview_start)
        overview_markup = self.html[overview_start:overview_end]
        self.assertIn('id="upload-title"', overview_markup)
        for metric_id in ('id="metric-arrival"', 'id="metric-duration"', 'id="metric-rooms"'):
            self.assertIn(metric_id, overview_markup)
        self.assertLess(overview_markup.index('id="upload-title"'), overview_markup.index('id="metric-arrival"'))
        self.assertLess(overview_markup.index('id="metric-arrival"'), overview_markup.index('id="metric-duration"'))
        self.assertLess(overview_markup.index('id="metric-duration"'), overview_markup.index('id="metric-rooms"'))
        self.assertIn(
            'class="daily-overview" aria-label="日报处理概览"',
            overview_markup,
        )
        self.assertIn(
            ".daily-overview { display: grid; grid-template-columns: minmax(320px, 1.55fr) repeat(3, minmax(0, 1fr));",
            self.styles,
        )
        self.assertIn(".daily-overview > .metric-card", self.styles)
        self.assertIn(
            ".daily-overview > .metric-card { align-self: stretch; display: flex; flex-direction: column; justify-content: center; height: auto; min-height: 0;",
            self.styles,
        )
        self.assertIn(".daily-overview > .metric-card::after", self.styles)
        self.assertNotIn("width: max-content", self.styles)
        self.assertIn("height: auto; min-height: 0", self.styles)
        self.assertIn(".daily-overview { grid-template-columns: 1fr;", self.styles)
        self.assertIn("@media (min-width: 701px)", self.styles)
        self.assertIn(".daily-overview .dropzone {", self.styles)
        self.assertIn("grid-template-columns: 28px minmax(0, 1fr)", self.styles)
        self.assertIn("min-height: 72px", self.styles)
        self.assertIn(".daily-overview .upload-footer", self.styles)
        self.assertIn("min-height: 44px", self.styles)
        self.assertIn("min-width: 96px", self.styles)

    def test_upload_panel_has_compact_action_footer(self) -> None:
        self.assertIn('class="panel-heading upload-heading"', self.html)
        self.assertIn('class="upload-footer"', self.html)
        self.assertIn(".upload-panel .primary-button", self.styles)
        self.assertIn("min-width: 118px", self.styles)
        self.assertNotIn("width: calc(100% - 48px)", self.styles)

    def test_removed_upload_labels_do_not_return(self) -> None:
        upload_start = self.html.index('class="panel upload-panel"')
        upload_end = self.html.index("</section>", upload_start)
        upload_markup = self.html[upload_start:upload_end]
        self.assertNotIn("本月留痕", upload_markup)
        self.assertNotIn("01 / UPLOAD", upload_markup)


if __name__ == "__main__":
    unittest.main(verbosity=2)
