# -*- coding: utf-8 -*-

"""
"""

# Third party imports
from qtpy.QtCore import Qt
from qtpy.QtWidgets import (QDialogButtonBox, QLabel, QPushButton,
                            QVBoxLayout,)

# Local imports
from anaconda_navigator.utils.analytics import GATracker
from anaconda_navigator.widgets import ButtonCancel
from anaconda_navigator.widgets.dialogs import DialogBase


class DialogUpdateApplication(DialogBase):
    """
    """

    def __init__(self, version):
        super(DialogUpdateApplication, self).__init__()
        self.tracker = GATracker()

        self.label = QLabel('Version "{0}" of Anaconda Navigator is available.'
                            '\n\n'
                            'Do you want to install the new '
                            'update?\n\n'.format(version))
        self.button_yes = QPushButton('Yes')
        self.button_no = ButtonCancel('No')
        self.bbox = QDialogButtonBox(Qt.Horizontal)

        # Widgets setup
        self.bbox.addButton(self.button_no, QDialogButtonBox.RejectRole)
        self.bbox.addButton(self.button_yes, QDialogButtonBox.AcceptRole)
        self.setMinimumWidth(260)
        self.setWindowTitle('Update Application')

        # Layouts
        layout = QVBoxLayout()
        layout.addWidget(self.label)
        layout.addWidget(self.bbox)
        self.setLayout(layout)

        # Signals
        self.button_yes.clicked.connect(self.accept)
        self.button_no.clicked.connect(self.reject)


def test():
    from anaconda_navigator.utils.qthelpers import qapplication
    app = qapplication(test_time=3)
    dialog = DialogUpdateApplication(version='1.2.0')
    dialog.update_style_sheet()
    if dialog.exec_():
        print('token', dialog.token)
    app.exec_()


if __name__ == '__main__':
    test()
