# -*- coding: utf-8 -*-
"""Uhr & Datum."""
from datetime import datetime
from PyQt5.QtCore import QTimer, Qt
from PyQt5.QtGui import QFont
from PyQt5.QtWidgets import QVBoxLayout, QLabel

from modules.base import DashboardModule, make_value_label, make_caption_label


class ClockModule(DashboardModule):
    def __init__(self, parent=None):
        super().__init__(parent)
        lay = QVBoxLayout(self)
        lay.setContentsMargins(4, 2, 4, 2)
        lay.setSpacing(2)

        self.time_lbl = make_value_label("--:--:--", size=22)
        self.date_lbl = make_caption_label("")
        lay.addWidget(self.time_lbl)
        lay.addWidget(self.date_lbl)

        self._timer = QTimer(self)
        self._timer.timeout.connect(self._refresh)
        self._timer.start(1000)
        self._refresh()

    def _refresh(self):
        now = datetime.now()
        self.time_lbl.setText(now.strftime("%H:%M:%S"))
        wochentage = ["Montag", "Dienstag", "Mittwoch", "Donnerstag",
                      "Freitag", "Samstag", "Sonntag"]
        self.date_lbl.setText(f"{wochentage[now.weekday()]}  {now.strftime('%d.%m.%Y')}")


MODULE_TITLE = "Uhr"
MODULE_CLASS = ClockModule
