# Copyright (C) 2025 by Animath
# SPDX-License-Identifier: GPL-3.0-or-later

from django.utils.translation import gettext_lazy as _
import django_tables2 as tables

from .models import Survey


class SurveyTable(tables.Table):
    survey_id = tables.LinkColumn(
        'survey:survey_detail',
        args=[tables.A('survey_id')],
        verbose_name=lambda: _("survey identifier").capitalize(),
    )

    nb_completed = tables.Column(
        verbose_name=_("completed").capitalize,
        accessor='survey_id'
    )

    def render_nb_completed(self, record):
        return f"{record.completed.count()}/{record.participants.count()}"

    class Meta:
        attrs = {
            'class': 'table table-condensed table-striped',
        }
        model = Survey
        fields = ('survey_id', 'name', 'invite_team', 'invite_coaches', 'tournament', 'nb_completed',)
        order_by = ('survey_id',)
