<%page expression_filter="h" args="section_data"/>

<%namespace name='static' file='../../static_content.html'/>
<%!
from django.utils.translation import ugettext as _
from openedx.core.djangolib.js_utils import js_escaped_string, dump_js_escaped_json
from courseware.courses import get_studio_url
from openedx.core.djangoapps.course_groups.partition_scheme import get_cohorted_user_partition
%>


<div class="cohort-management"
     data-cohorts_url="${section_data['cohorts_url']}"
     data-upload_cohorts_csv_url="${section_data['upload_cohorts_csv_url']}"
     data-course_cohort_settings_url="${section_data['course_cohort_settings_url']}"
     data-verified_track_cohorting_url="${section_data['verified_track_cohorting_url']}"
     data-is_ccx_enabled="${'true' if section_data['ccx_is_enabled'] else 'false'}"
>
</div>


<%block name="js_extra">
<%static:require_module module_name="js/groups/views/cohorts_dashboard_factory" class_name="CohortsFactory">
    <%
    cohorted_user_partition = get_cohorted_user_partition(course)
    content_groups = cohorted_user_partition.groups if cohorted_user_partition else []
    %>
    var cohortUserPartitionId = ${cohorted_user_partition.id if cohorted_user_partition else None | n, dump_js_escaped_json},
        contentGroups = [
            % for content_group in content_groups:
            {
                id: ${content_group.id | n, dump_js_escaped_json},
                name: "${content_group.name | n, js_escaped_string}",
                user_partition_id: cohortUserPartitionId
            },
            % endfor
        ];
    CohortsFactory(contentGroups, "${get_studio_url(course, 'group_configurations') | n, js_escaped_string}");
</%static:require_module>
</%block>
<div class="cohort-state-message"></div>
