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

###############
class Tableau_1_1(Page):
    def is_displayed(self):
        return self.group.tableau_1 == 'Tableau_1'
    form_model = 'player'
    form_fields = ['tab_1_{}'.format(i) for i in
                   range(1,14)]
###############
class Tableau_2_1(Page):
    def is_displayed(self):
        return self.group.tableau_1 == 'Tableau_2'
    form_model = 'player'
    form_fields = ['tab_2_{}'.format(i) for i in
                   range(1,14)]
###############
class Tableau_3_1(Page):
    def is_displayed(self):
        return self.group.tableau_1 == 'Tableau_3'
    form_model = 'player'
    form_fields = ['tab_3_{}'.format(i) for i in
                   range(1,14)]
###############
class Tableau_4_1(Page):
    def is_displayed(self):
        return self.group.tableau_1 == 'Tableau_4'
    form_model = 'player'
    form_fields = ['tab_4_{}'.format(i) for i in
                   range(1,14)]

###############
class Tableau_1_2(Page):
    def is_displayed(self):
        return self.group.tableau_2 == 'Tableau_1'
    form_model = 'player'
    form_fields = ['tab_1_{}'.format(i) for i in
                   range(1,14)]
###############
class Tableau_2_2(Page):
    def is_displayed(self):
        return self.group.tableau_2 == 'Tableau_2'
    form_model = 'player'
    form_fields = ['tab_2_{}'.format(i) for i in
                   range(1,14)]
###############
class Tableau_3_2(Page):
    def is_displayed(self):
        return self.group.tableau_2 == 'Tableau_3'
    form_model = 'player'
    form_fields = ['tab_3_{}'.format(i) for i in
                   range(1,14)]
###############
class Tableau_4_2(Page):
    def is_displayed(self):
        return self.group.tableau_2 == 'Tableau_4'
    form_model = 'player'
    form_fields = ['tab_4_{}'.format(i) for i in
                   range(1,14)]

##########
class Tableau_1_3(Page):
    def is_displayed(self):
        return self.group.tableau_3 == 'Tableau_1'
    form_model = 'player'
    form_fields = ['tab_1_{}'.format(i) for i in
                   range(1,14)]
###############
class Tableau_2_3(Page):
    def is_displayed(self):
        return self.group.tableau_3 == 'Tableau_2'
    form_model = 'player'
    form_fields = ['tab_2_{}'.format(i) for i in
                   range(1,14)]
###############
class Tableau_3_3(Page):
    def is_displayed(self):
        return self.group.tableau_3 == 'Tableau_3'
    form_model = 'player'
    form_fields = ['tab_3_{}'.format(i) for i in
                   range(1,14)]
###############
class Tableau_4_3(Page):
    def is_displayed(self):
        return self.group.tableau_3 == 'Tableau_4'
    form_model = 'player'
    form_fields = ['tab_4_{}'.format(i) for i in
                   range(1,14)]


##########
class Tableau_1_4(Page):
    def is_displayed(self):
        return self.group.tableau_4 == 'Tableau_1'
    form_model = 'player'
    form_fields = ['tab_1_{}'.format(i) for i in
                   range(1,14)]
###############
class Tableau_2_4(Page):
    def is_displayed(self):
        return self.group.tableau_4 == 'Tableau_2'
    form_model = 'player'
    form_fields = ['tab_2_{}'.format(i) for i in
                   range(1,14)]
###############
class Tableau_3_4(Page):
    def is_displayed(self):
        return self.group.tableau_4 == 'Tableau_3'
    form_model = 'player'
    form_fields = ['tab_3_{}'.format(i) for i in
                   range(1,14)]
###############
class Tableau_4_4(Page):
    def is_displayed(self):
        return self.group.tableau_4 == 'Tableau_4'
    form_model = 'player'
    form_fields = ['tab_4_{}'.format(i) for i in
                   range(1,14)]
###############
class Results(Page):
    def vars_for_template(self):
        return {
            'ligne': self.group.ligne_random,
        }
###############
class ResultsWaitPage(WaitPage):
    def after_all_players_arrive(self):
        self.group.calculate_payoff()

###############
page_sequence = [
    Tableau_1_1,
    Tableau_2_1,
    Tableau_3_1,
    Tableau_4_1,
    ResultsWaitPage,
    Results,
    Tableau_1_2,
    Tableau_2_2,
    Tableau_3_2,
    Tableau_4_2,
    Tableau_1_3,
    Tableau_2_3,
    Tableau_3_3,
    Tableau_4_3,
    Tableau_1_4,
    Tableau_2_4,
    Tableau_3_4,
    Tableau_4_4,

]
#
#
#initial_page_sequence = [
#    Tableau_1,
#    Tableau_2,
#    Tableau_3,
#    Tableau_4,
#]
#
#end_sequence = [
#    ResultsWaitPage,
#    Results
#]
#
#page_sequence = [
#
#]
#
#class MyPage(Page):
#    def inner_dispatch(self):
#        page_seq = int(self.__class__.__name__.split('_')[0])
#        page_to_show = json.loads(self.group.page_sequence)[page_seq]
#        self.__class__ = globals()[page_to_show]
#        return super(globals()[page_to_show], self).inner_dispatch()
#
#
#for i, _ in enumerate(initial_page_sequence):
#    NewClassName = "Page_{}".format(i)
#    A = type(NewClassName, (MyPage,), {})
#    locals()[NewClassName] = A
#    page_sequence.append(locals()[NewClassName])
#page_sequence = [page_sequence + end_sequence]

