from otree.api import *


doc = """
Your app description
"""


class C(BaseConstants):
    NAME_IN_URL = 'monotonic_sliders'
    PLAYERS_PER_GROUP = None
    NUM_ROUNDS = 1
    MONOTONIC_FIELDS = ['x1', 'x2', 'x3', 'x4', 'x5']


class Subsession(BaseSubsession):
    pass


class Group(BaseGroup):
    pass


def make_field():
    return models.IntegerField(choices=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], widget=widgets.RadioSelectHorizontal)


class Player(BasePlayer):
    x1 = make_field()
    x2 = make_field()
    x3 = make_field()
    x4 = make_field()
    x5 = make_field()


# PAGES
class MyPage(Page):
    form_model = 'player'
    form_fields = C.MONOTONIC_FIELDS

    @staticmethod
    def js_vars(player: Player):
        return dict(fields=C.MONOTONIC_FIELDS)

    @staticmethod
    def error_message(player: Player, values):
        radio_values = [values[f] for f in C.MONOTONIC_FIELDS]
        sorted_values = list(reversed(sorted(radio_values)))
        if radio_values != sorted_values:
            return "Values must be decreasing"


class ResultsWaitPage(WaitPage):
    pass


class Results(Page):
    pass


page_sequence = [MyPage, ResultsWaitPage, Results]
