from __future__ import annotations

import wx
from wx.adv import Wizard, WizardPage, EVT_WIZARD_PAGE_SHOWN

from clarabot_nano.control.icon import get_wx_nano_icon
from clarabot_nano.control.label import AutoHeightWrappedStaticText
from clarabot_nano.resource import get_resource_path


class SimpleWizard(Wizard):
    def __init__(self, parent):
        bitmap = wx.Bitmap(str(get_resource_path("image", "wiz.png")))
        Wizard.__init__(
            self,
            parent,
            title=gettext("Basic configuration wizard"),
            style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
            bitmap=bitmap,
        )
        self.SetPageSize(wx.Size(420, 360))
        self.SetIcon(get_wx_nano_icon())
        self.pages = []

        self.Bind(EVT_WIZARD_PAGE_SHOWN, self._on_page_shown, self)

    def _on_page_shown(self, event):
        event.GetPage().Layout()


class SimpleWizardPage(WizardPage):
    def __init__(self, parent: SimpleWizard, description: str, bitmap: wx.Bitmap = wx.NullBitmap):
        WizardPage.__init__(self, parent, bitmap)
        self._pages = parent.pages
        self._pages.append(self)

        self.layout = wx.BoxSizer(wx.VERTICAL)

        self._d = description
        self.description = AutoHeightWrappedStaticText(self, wx.ID_ANY, description)
        self.layout.Add(self.description, 0, wx.EXPAND | wx.BOTTOM, 12)

        self.SetSizer(self.layout)

    def GetNext(self):
        i = self._pages.index(self) + 1
        if i < len(self._pages):
            return self._pages[i]

    def GetPrev(self):
        i = self._pages.index(self) - 1
        if i >= 0:
            return self._pages[i]
