# standard
from __future__ import annotations

from pathlib import Path
from typing import Optional

# PyQGIS
from qgis.PyQt import uic
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtWidgets import QWidget

# Project
from oslandia.__about__ import DIR_PLUGIN_ROOT
from oslandia.gui.onboarding.wdg_base_page import WidgetPageBase


class NewsFeedFeaturesPage(WidgetPageBase):
    def __init__(self, parent: Optional[QWidget] = None):
        super().__init__(parent)
        uic.loadUi(Path(__file__).parent / f"{Path(__file__).stem}.ui", self)

        self.wdg_settings_rss.load_settings()
        self.btn_next.clicked.connect(lambda: self.end_signal.emit())
        self.btn_next.clicked.connect(self.wdg_settings_rss.save_settings)
        self.btn_next.setIcon(
            QIcon(str(DIR_PLUGIN_ROOT / "resources/images/rocket.svg"))
        )

        img_list = [
            DIR_PLUGIN_ROOT
            / "resources/images/onboarding/featured_screenshot_news_feed_01.png",
            DIR_PLUGIN_ROOT
            / "resources/images/onboarding/featured_screenshot_news_feed_02.png",
        ]
        self.wdg_images.set_image_list(img_list)

        # Hide unwanted settings widgets
        for widget in (
            self.wdg_settings_rss.lbl_feed_url,
            self.wdg_settings_rss.lbl_rss_url,
            self.wdg_settings_rss.lbl_filter_categories,
            self.wdg_settings_rss.cbx_rss_user_filters,
            self.wdg_settings_rss.lbl_reset_news_history,
            self.wdg_settings_rss.btn_reset_rss_history,
        ):
            widget.setVisible(False)
        self.wdg_settings_rss.grp_feed.setTitle("")
