"""
S5 — Bluetooth empty state (no paired devices).

Spec: glyph card @ (272,110) 96×96 r24; headline @ y220; sub @ y252;
CTA "Pair new device" @ (226,304) 188×46 FOCUSED; adapter meta @ y366.
"""

from __future__ import annotations

import pygame

from ..design import tokens as t
from ..shared import widgets as w
from ..shared import fonts, icons, render


class EmptyScreen:
    name = "bt-empty"

    def __init__(self, app):
        self.app = app
        self.focus = 0   # only the CTA

    def on_action(self, action):
        if action == "a":
            from .pair import PairScreen
            self.app.push(PairScreen(self.app))
        elif action == "b":
            self.app.pop()

    def update(self, dt_ms):
        pass

    def draw(self, surf):
        w.status_bar(surf, title="Bluetooth", back=True)

        # glyph card 96×96 @ (272,110)
        card = render.rounded_gradient((96, 96), t.Color.SURFACE_BASE, t.Color.BG_MID, 24, 160)
        glyph = icons.icon("ph-bluetooth", 48, t.Color.TEXT_SECONDARY)
        card.blit(glyph, ((96 - 48) // 2, (96 - 48) // 2))
        surf.blit(card, (272, 110))

        # headline centered @ y220
        head = fonts.render(t.Type.HERO, "No devices yet", t.Color.TEXT_PRIMARY)
        surf.blit(head, ((640 - head.get_width()) // 2, 220))

        # two-line sub centered @ y252
        sub_lines = ["Pair your first Bluetooth device to start using",
                     "wireless audio, controllers and peripherals."]
        sy = 254
        for line in sub_lines:
            s = fonts.render(t.Type.BODY, line, t.Color.TEXT_SECONDARY)
            surf.blit(s, ((640 - s.get_width()) // 2, sy))
            sy += s.get_height() + 2

        # CTA @ (226,304) 188×46 focused
        w.button(surf, pygame.Rect(226, 304, 188, 46), "Pair new device",
                 icon_name="ph-plus-circle", focused=True)

        # adapter meta @ y366 centered
        meta = fonts.render(t.Type.MONO_TECH, "● Adapter hci0 ready", t.Color.TEXT_MUTED)
        surf.blit(meta, ((640 - meta.get_width()) // 2, 366))

        w.footer_hints(surf, [("A", "pair"), ("B", "back")])
