"""
next_up_bar.py — Banner der vises når en sang er færdig.
"""

from PyQt6.QtWidgets import (
    QFrame, QHBoxLayout, QVBoxLayout, QLabel, QPushButton,
)
from PyQt6.QtCore import pyqtSignal


class NextUpBar(QFrame):
    play_next_clicked = pyqtSignal()

    def __init__(self, parent=None):
        super().__init__(parent)
        self.setObjectName("next_up_frame")
        self.hide()
        self._build_ui()

    def _build_ui(self):
        layout = QHBoxLayout(self)
        layout.setContentsMargins(16, 10, 16, 10)

        # Tekst
        text_layout = QVBoxLayout()
        text_layout.setSpacing(2)

        self._label = QLabel("NÆSTE SANG KLAR")
        self._label.setObjectName("next_up_label")
        text_layout.addWidget(self._label)

        self._title = QLabel("—")
        self._title.setObjectName("next_up_title")
        text_layout.addWidget(self._title)

        self._sub = QLabel("—")
        self._sub.setObjectName("next_up_sub")
        text_layout.addWidget(self._sub)

        layout.addLayout(text_layout)
        layout.addStretch()

        # Knap
        self._btn = QPushButton("▶  AFSPIL NÆSTE")
        self._btn.setObjectName("btn_play_next")
        self._btn.setFixedHeight(44)
        self._btn.setMinimumWidth(160)
        self._btn.clicked.connect(self.play_next_clicked.emit)
        layout.addWidget(self._btn)

    def show_next(self, title: str, artist: str, dances: list[str]):
        dance_str = "Dans: " + ", ".join(dances) if dances else ""
        sub = f"{artist}{'  ·  ' + dance_str if dance_str else ''}"
        self._title.setText(title)
        self._sub.setText(sub)
        self.show()

    def hide_bar(self):
        self.hide()
