<% field_id = "questionnaire_responses_#{answer_idx}" %>

<% if answer.question.separator? %>
  <%= render partial: "decidim/forms/questionnaires/answers/#{answer.question.question_type}", locals: { answer: answer, answer_form: answer_form, answer_idx: answer_idx, field_id: field_id, disabled: disabled } %>
  <%= answer_form.hidden_field :question_id %>
<% elsif answer.question.title_and_description? %>
  <%= label_tag field_id, translated_attribute(answer.question.body), class: "questionnaire-title_and_description" %>
  <% if translated_attribute(answer.question.description).present? %>
    <div class="help-title_and_description ">
      <%= decidim_sanitize_editor translated_attribute(answer.question.description) %>
    </div>
  <% end %>
  <%= render partial: "decidim/forms/questionnaires/answers/#{answer.question.question_type}", locals: { answer: answer, answer_form: answer_form, answer_idx: answer_idx, field_id: field_id, disabled: disabled } %>
  <%= answer_form.hidden_field :question_id %>
<% else %>
  <% case answer.question.question_type %>
  <% when "single_option", "multiple_option", "sorting" %>
    <label class="questionnaire-question"><%= answer.label(cleaned_answer_idx) %></label>
  <% else %>
    <%= label_tag field_id, answer.label(cleaned_answer_idx), class: "questionnaire-question" %>
  <% end %>

  <% if translated_attribute(answer.question.description).present? %>
    <div class="help-text">
      <%= decidim_sanitize_editor translated_attribute(answer.question.description) %>
    </div>
  <% end %>

  <%= render partial: "decidim/forms/questionnaires/answers/#{answer.question.question_type}", locals: { answer: answer, answer_form: answer_form, answer_idx: answer_idx, field_id: field_id, disabled: disabled, maxlength: (answer.question.max_characters if answer.question.max_characters.positive?) } %>

  <%= answer_form.hidden_field :question_id %>

  <small class="form-error max-choices-alert"><%= t(".max_choices_alert") %></small>

  <% answer.errors.full_messages.each do |msg| %>
    <small class="form-error is-visible"><%= msg %></small>
  <% end %>
<% end %>