<%page expression_filter="h"/>
<%! from openedx.core.djangolib.markup import HTML %>
<%
  def is_radio_input(choice_id):
    return input_type == 'radio' and ((isinstance(value, basestring) and (choice_id == value)) or (
      not isinstance(value, basestring) and choice_id in value
    ))
%>
<form class="choicegroup capa_inputtype" id="inputtype_${id}">
    <fieldset ${HTML(describedby_html)}>
      % if response_data['label']:
        <legend id="${id}-legend" class="response-fieldset-legend field-group-hd">${response_data['label']}</legend>
      % endif
      % for description_id, description_text in response_data['descriptions'].items():
        <p class="question-description" id="${description_id}">${description_text}</p>
      % endfor
        % for choice_id, choice_label in choices:
          <div class="field" aria-live="polite" aria-atomic="true">
            <%
              label_class = 'response-label field-label label-inline'
            %>
            <label id="${id}-${choice_id}-label"
                ## If the student has selected this choice...
                % if is_radio_input(choice_id):
                <%
                    if status == 'correct':
                        correctness = 'correct'
                    elif status == 'partially-correct':
                        correctness = 'partially-correct'
                    elif status == 'incorrect':
                        correctness = 'incorrect'
                    else:
                        correctness = None
                %>
                    % if correctness and not show_correctness == 'never':
                        <% label_class += ' choicegroup_' + correctness %>
                    % endif
                % endif
                class="${label_class}"
                ${HTML(describedby_html)}
                >
                <input type="${input_type}" name="input_${id}${name_array_suffix}" id="input_${id}_${choice_id}" class="field-input input-${input_type}" value="${choice_id}"
                ## If the student selected this choice...
                % if is_radio_input(choice_id):
                checked="true"
                % elif input_type != 'radio' and choice_id in value:
                checked="true"
                % endif
                /> ${HTML(choice_label)}

                % if is_radio_input(choice_id):
                  % if status in ('correct', 'partially-correct', 'incorrect') and not show_correctness == 'never':
                    <span class="sr status" id="${id}-${choice_id}-labeltext">${status.display_name}</span>
                  % endif
                % endif
            </label>
          </div>
        % endfor
        <span id="answer_${id}"></span>
    </fieldset>
    <div class="indicator-container">
        % if input_type == 'checkbox' or not value:
            <span class="status ${status.classname if show_correctness != 'never' else 'unanswered'}" id="status_${id}" data-tooltip="${status.display_tooltip}">
                <span class="sr">${status.display_tooltip}</span>
            </span>
        % endif
    </div>
    % if show_correctness == "never" and (value or status not in ['unsubmitted']):
    <div class="capa_alert">${submitted_message}</div>
    %endif
    % if msg:
    <span class="message">${HTML(msg)}</span>
    % endif
</form>
