from otree.api import Currency as c, currency_range
from . import models
from ._builtin import Page, WaitPage
from .models import Constants


#################################################
#################################################
class ParticipantPage(Page):
    form_model = 'player'
    form_fields = ['pass_phrase']

    def pass_phrase_error_message(self, value):
        if value == Constants.c_passphrases["Expert"]:
            self.player.Role = "Expert"
        elif value == Constants.c_passphrases["Presenter"]:
            self.player.Role = "Presenter"
        elif value == Constants.c_passphrases["MasterOfCeremony"]:
            self.player.Role = "MasterOfCeremony"
        else:
            return "Cette phrase n'est pas connue"

    def vars_for_template(self):
        # Copy the global variables from connect_and_filter if it's not already done
        if (self.player.profile == "Not filled") & (self.player.pseudo_id == "Not filled"):
            self.player.profile = self.player.participant.vars['profile']
            self.player.pseudo_id = self.player.participant.vars['pseudo_id']
        return {
            "nname": self.player.profile + "-" + str(self.player.id_in_subsession),
        }


# -----------------------------------------------
class ExpertDisciplinePage(Page):
    form_model = 'player'
    form_fields = ['expert_discipline']

    def is_displayed(self):
        return self.player.Role == "Expert"


class ExpertPage(Page):
    def is_displayed(self):
        return self.player.Role == "Expert"


# -----------------------------------------------
class PresenterPage(Page):
    def is_displayed(self):
        return self.player.Role == "Presenter"


# -----------------------------------------------
class MCPage(Page):
    def is_displayed(self):
        return self.player.Role == "MasterOfCeremony"

    def vars_for_template(self):
        return{
            "multi_choice_questions_list": self.subsession.get_questions_and_parameters("multi_choice"),
            "value_questions_list": self.subsession.get_questions_and_parameters("value"),
        }


#################################################
#################################################
page_sequence = [
    ParticipantPage,
    ExpertDisciplinePage,
    ExpertPage,
    PresenterPage,
    MCPage,
]
