# -*- coding: utf-8 -*-
"""
LMS index (home) page.
"""
from bok_choy.page_object import PageObject
from . import BASE_URL

BANNER_SELECTOR = 'section.home header div.outer-wrapper div.title hgroup h1'
INTRO_VIDEO_SELECTOR = 'div.play-intro'
VIDEO_MODAL_SELECTOR = 'section#video-modal.modal.home-page-video-modal.video-modal'


class IndexPage(PageObject):
    """
    LMS index (home) page, the default landing page for Open edX users when they are not logged in
    """
    def __init__(self, browser):
        """Initialize the page.

        Arguments:
            browser (Browser): The browser instance.
        """
        super(IndexPage, self).__init__(browser)

    url = "{base}/".format(base=BASE_URL)

    def is_browser_on_page(self):
        """
        Returns a browser query object representing the video modal element
        """
        element = self.q(css=BANNER_SELECTOR)
        return element.visible and element.text[0] == "Welcome to Open edX!"

    @property
    def banner_element(self):
        """
        Returns a browser query object representing the video modal element
        """
        return self.q(css=BANNER_SELECTOR)

    @property
    def intro_video_element(self):
        """
        Returns a browser query object representing the video modal element
        """
        return self.q(css=INTRO_VIDEO_SELECTOR)

    @property
    def video_modal_element(self):
        """
        Returns a browser query object representing the video modal element
        """
        return self.q(css=VIDEO_MODAL_SELECTOR)
