from ._builtin import Page
import random


class IntroductionT(Page):
    def is_displayed(self):
        if self.participant.vars['chosen_app_urns'] == 1:
            pass
        else:
            return self.round_number == 1


class ComprehensionT(Page):
    form_model = 'player'
    form_fields = ['true_false_1', 'true_false_2', 'true_false_3', 'true_false_7']

    def is_displayed(self):
        if self.participant.vars['chosen_app_urns'] == 1:
            pass
        else:
            return self.round_number == 1

    def get_form_fields(self):
        fields = self.form_fields
        random.shuffle(fields)
        return fields


class FinalT(Page):
    form_model = 'player'
    form_fields = ['comments']

    def is_displayed(self):
        if self.participant.vars['chosen_app_urns'] == 1:
            pass
        else:
            return self.round_number == 1


class ThankYouT(Page):
    form_model = 'player'
    form_fields = ['personal_info']

    def is_displayed(self):
        if self.participant.vars['chosen_app_urns'] == 1:
            pass
        else:
            return self.round_number == 4


class DrawChoice2(Page):
    form_model = 'player'
    form_fields = ['urn_choice_red_2', 'urn_choice_blue_2']

    def is_displayed(self):
        if self.participant.vars['chosen_app_urns'] == 1:
            pass
        else:
            return self.player.information_channel_2 == 'Draw a ball from the actual urn selected for your 4-member group in this round'

    def get_form_fields(self):
        fields = self.form_fields
        random.shuffle(fields)
        return fields


class DrawChoice3(Page):
    form_model = 'player'
    form_fields = ['urn_choice_red_3', 'urn_choice_blue_3']

    def is_displayed(self):
        if self.participant.vars['chosen_app_urns'] == 1:
            pass
        else:
            return self.player.information_channel_3 == 'Draw a ball from the actual urn selected for your 4-member group in this round'

    def get_form_fields(self):
        fields = self.form_fields
        random.shuffle(fields)
        return fields


class DrawChoice4(Page):
    form_model = 'player'
    form_fields = ['urn_choice_red_4', 'urn_choice_blue_4']

    def is_displayed(self):
        if self.participant.vars['chosen_app_urns'] == 1:
            pass
        else:
            return self.player.information_channel_4 == 'Draw a ball from the actual urn selected for your 4-member group in this round'

    def get_form_fields(self):
        fields = self.form_fields
        random.shuffle(fields)
        return fields


class GuessChoice2(Page):
    form_model = 'player'
    form_fields = ['social_info_2_R', 'social_info_2_B']

    def is_displayed(self):
        if self.participant.vars['chosen_app_urns'] == 1:
            pass
        else:
            return self.player.information_channel_2 == 'See the group urn guess by the player in position 1'

    def get_form_fields(self):
        fields = self.form_fields
        random.shuffle(fields)
        return fields


class GuessChoice3(Page):
    form_model = 'player'
    form_fields = ['social_info_3_RR', 'social_info_3_RB', 'social_info_3_BR', 'social_info_3_BB']

    def is_displayed(self):
        if self.participant.vars['chosen_app_urns'] == 1:
            pass
        else:
            return self.player.information_channel_3 == 'See the respective group urn guesses by players in position 1 and position 2'

    def get_form_fields(self):
        fields = self.form_fields
        random.shuffle(fields)
        return fields


class GuessChoice4(Page):
    form_model = 'player'
    form_fields = ['social_info_4_RRR', 'social_info_4_RRB', 'social_info_4_RBR', 'social_info_4_BRR',
                   'social_info_4_BBB', 'social_info_4_BBR', 'social_info_4_BRB', 'social_info_4_RBB']

    def is_displayed(self):
        if self.participant.vars['chosen_app_urns'] == 1:
            pass
        else:
            return self.player.information_channel_4 == 'See the respective group urn guesses by players in position 1, position 2, and position 3'

    def get_form_fields(self):
        fields = self.form_fields
        random.shuffle(fields)
        return fields


class PageOneT(Page):
    form_model = 'player'
    form_fields = ['urn_choice_position1_red', 'urn_choice_position1_blue']

    def get_form_fields(self):
        fields = self.form_fields
        random.shuffle(fields)
        return fields

    def is_displayed(self):
        if self.participant.vars['chosen_app_urns'] == 1:
            pass
        else:
            return self.round_number == self.participant.vars['task_rounds_urn2']['PageOneT']


class PageTwoT(Page):
    form_model = 'player'
    form_fields = ['information_channel_2']

    def get_form_fields(self):
        fields = self.form_fields
        random.shuffle(fields)
        return fields

    def is_displayed(self):
        if self.participant.vars['chosen_app_urns'] == 1:
            pass
        else:
            return self.round_number == self.participant.vars['task_rounds_urn2']['PageTwoT']


class PageThreeT(Page):
    form_model = 'player'
    form_fields = ['outcome3_P1', 'outcome3_P2',
                   'outcome4_P1', 'outcome4_P2', 'information_channel_3']

    def is_displayed(self):
        if self.participant.vars['chosen_app_urns'] == 1:
            pass
        else:
            return self.round_number == 1


class PageFourT(Page):
    form_model = 'player'
    form_fields = ['information_channel_4']

    def get_form_fields(self):
        fields = self.form_fields
        random.shuffle(fields)
        return fields

    def is_displayed(self):
        if self.participant.vars['chosen_app_urns'] == 1:
            pass
        else:
            return self.round_number == self.participant.vars['task_rounds_urn2']['PageFourT']


page_sequence = [

    IntroductionT,

    ComprehensionT,

    PageThreeT,

    DrawChoice3,

    GuessChoice3,

    PageOneT,

    PageTwoT,

    DrawChoice2,

    GuessChoice2,

    PageFourT,

    DrawChoice4,

    GuessChoice4

]
