# lottery_app/pages.py
from otree.api import *
from .models import Constants, Player

# ---- Intro ----
class Intro(Page):
    def is_displayed(self):
        return True

    def vars_for_template(self):
        return dict(
            ui_mode=self.player.participant.vars.get('ui_mode', 'single'),
            schedule=Constants.SINGLE_SCHEDULE,
        )

# 原本 S1~S9 可以保留作備份，就不重貼

# ---- Single UI：3 頁，每頁 3 個 round ----
class SingleBlock1(Page):
    form_model = 'player'
    form_fields = ['s1', 's2', 's3']

    def is_displayed(self):
        return self.player.participant.vars.get('ui_mode') == 'single'


class SingleBlock2(Page):
    form_model = 'player'
    form_fields = ['s4', 's5', 's6']

    def is_displayed(self):
        return self.player.participant.vars.get('ui_mode') == 'single'


class SingleBlock3(Page):
    form_model = 'player'
    form_fields = ['s7', 's8', 's9']

    def is_displayed(self):
        return self.player.participant.vars.get('ui_mode') == 'single'


# ---- Grouped UI：維持原本三頁 ----
class G1(Page):
    form_model = 'player'
    form_fields = ['g1a', 'g1b', 'g1c']
    def is_displayed(self): return self.player.participant.vars.get('ui_mode') == 'grouped'

class G2(Page):
    form_model = 'player'
    form_fields = ['g2a', 'g2b', 'g2c']
    def is_displayed(self): return self.player.participant.vars.get('ui_mode') == 'grouped'

class G3(Page):
    form_model = 'player'
    form_fields = ['g3a', 'g3b', 'g3c']
    def is_displayed(self): return self.player.participant.vars.get('ui_mode') == 'grouped'


# ---- Results ----
class Results(Page):
    def is_displayed(self):
        return True


page_sequence = [
    Intro,
    # single 組：三頁，每頁 3 個 round，用 tabs 切
    SingleBlock1,
    SingleBlock2,
    SingleBlock3,
    # grouped 組：維持三頁
    G1, G2, G3,
    Results,
]
                                                                   'player'
    form_fields = ['g3a', 'g3b', 'g3c']
    def is_displayed(self): return self.player.participant.vars.get('ui_mode') == 'grouped'


# ---- Results ----
class Results(Page):
    def is_displayed(self):
        return True


page_sequence = [
    Intro,
    # single：改成一頁 tabs（原本的 S1~S9 不再放這裡）
    SingleTabs,
    # grouped：維持三頁
    G1, G2, G3,
    Results,
]
                                                                                   s ----
class Results(Page):
    def is_displayed(self):
        return True

page_sequence = [
    Intro,
    # single（顯示條件內部會過濾）
    S1, S2, S3, S4, S5, S6, S7, S8, S9,
    # grouped（顯示條件內部會過濾）
    G1, G2, G3,
    Results,
]
                                                                                                                                                                                                                                     ped'


# ---- Results ----
class Results(Page):
    @staticmethod
    def is_displayed(player: Player):
        return True


page_sequence = [
    Intro,
    # single 版面（is_displayed 會過濾）
    S1, S2, S3, S4, S5, S6, S7, S8, S9,
    # grouped 版面（is_displayed 會過濾）
    G1, G2, G3,
    Results,
]
                                                                                                                                                                           ed'].append(tup)


class Result