from admin_tools.dashboard import modules, Dashboard, AppIndexDashboard


class CustomIndexDashboard(Dashboard):
    """
    Custom index dashboard for src.
    """

    columns = 3

    def init_with_context(self, context):
        self.children.append(
            modules.ModelList(
                "Groupes et utilisateurs",
                deletable=False,
                draggable=False,
                models=("django.contrib.auth.*", "accounts.*"),
            )
        )
        self.children.append(
            modules.ModelList(
                "Structures",
                deletable=False,
                draggable=False,
                models=("organizations.*",),
            )
        )
        self.children.append(
            modules.ModelList(
                "Aides",
                deletable=False,
                draggable=False,
                models=("aids.*",),
            )
        )
        self.children.append(
            modules.ModelList(
                "Aides - gestion avancées",
                deletable=False,
                draggable=False,
                models=(
                    "backers.*",
                    "programs.*",
                    "categories.*",
                    "keywords.*",
                ),
            )
        )
        self.children.append(
            modules.ModelList(
                "Périmètres",
                deletable=False,
                draggable=False,
                models=("geofr.*",),
            )
        )
        self.children.append(
            modules.ModelList(
                "Projets",
                deletable=False,
                draggable=False,
                models=("projects.*",),
            )
        )
        self.children.append(
            modules.ModelList(
                "Alertes",
                deletable=False,
                draggable=False,
                models=("alerts.*",),
            )
        )
        self.children.append(
            modules.ModelList(
                "Notifications",
                deletable=False,
                draggable=False,
                models=("notifications.*",),
            )
        )
        self.children.append(
            modules.ModelList(
                "Contenu éditorial",
                deletable=False,
                draggable=False,
                models=("blog.*", "pages.*", "upload.*"),
            )
        )
        self.children.append(
            modules.ModelList(
                "Test d'eligibilité",
                deletable=False,
                draggable=False,
                models=("eligibility.*",),
            )
        )
        self.children.append(
            modules.Group(
                title="Pages Personnalisées",
                display="tabs",
                deletable=False,
                draggable=False,
                children=[
                    modules.ModelList(
                        "Configuration",
                        models=(
                            "search.models.SearchPage",
                            "search.models.MinisiteTab",
                        ),
                    ),
                    modules.ModelList(
                        "Espace Contributeur",
                        models=(
                            "search.models.SearchPageLite",
                            "search.models.MinisiteTabLite",
                        ),
                    ),
                ],
            )
        )
        self.children.append(
            modules.Group(
                title="Statistiques",
                display="tabs",
                deletable=False,
                draggable=False,
                children=[
                    modules.ModelList(
                        "Aides",
                        models=(
                            "stats.models.AidViewEvent",
                            "stats.models.AidContactClickEvent",
                            "stats.models.AidOriginUrlClickEvent",
                            "stats.models.AidApplicationUrlClickEvent",
                            "stats.models.AidCreateDSFolderEvent",
                            "stats.models.AidSearchEvent",
                            "stats.models.AidEligibilityTestEvent",
                        ),
                    ),
                    modules.ModelList(
                        "Projets",
                        models=(
                            "stats.models.PublicProjectSearchEvent",
                            "stats.models.ValidatedProjectSearchEvent",
                            "stats.models.PublicProjectViewEvent",
                        ),
                    ),
                    modules.ModelList(
                        "Autres",
                        models=(
                            "stats.models.ProgramViewEvent",
                            "stats.models.BackerViewEvent",
                            "stats.models.PostViewEvent",
                            "stats.models.AccountRegisterFromNextpagewarningClickEvent",
                            "stats.models.Event",
                            "stats.models.PromotionDisplayEvent",
                            "stats.models.PromotionClickEvent",
                            "stats.models.ContactFormSendEvent",
                        ),
                    ),
                ],
            )
        )
        self.children.append(
            modules.RecentActions(
                "Actions récentes",
                5,
                deletable=False,
                draggable=False,
            )
        )
        self.children.append(
            modules.Group(
                title="Configuration Système",
                display="tabs",
                deletable=False,
                draggable=False,
                children=[
                    modules.ModelList(
                        "Data et API",
                        models=(
                            "exporting.*",
                            "dataproviders.*",
                            "rest_framework.authtoken.*",
                        ),
                    ),
                    modules.ModelList(
                        "Config du site",
                        models=(
                            "django.contrib.sites.*",
                            "django_otp.plugins.otp_totp.*",
                        ),
                    ),
                    modules.ModelList(
                        "Tâches périodiques",
                        models=("django_celery_beat.*",),
                    ),
                ],
            )
        )


class CustomAppIndexDashboard(AppIndexDashboard):
    """
    Custom app index dashboard for src.
    """

    # we disable title because its redundant with the model list module
    title = ""

    def __init__(self, *args, **kwargs):
        AppIndexDashboard.__init__(self, *args, **kwargs)

        # append a model list module and a recent actions module
        self.children += [
            modules.ModelList(self.app_title, self.models),
            modules.RecentActions(
                "Actions récentes", include_list=self.get_app_content_types(), limit=5
            ),
        ]

    def init_with_context(self, context):
        """
        Use this method if you need to access the request context.
        """
        return super(CustomAppIndexDashboard, self).init_with_context(context)
