<%
# Copyright (C) 2011 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
%>

<%
    editable ||= false
%>
<div <%= 'class=file-upload-question-holder' if question_type.entry_type == 'file' %> >
  <% value = (@stored_params.present?) ? h(@stored_params["question_#{hash_get(question, :id)}"]) : h(hash_get(user_answer, :text).to_s) %>
<% if question_type.entry_type == "text_box" %>
  <input type="text" name="question_<%= hash_get(question, :id) %>" value="<%= value %>" class="question_input" autocomplete='off' <%= 'readonly="readonly"' unless editable %> aria-label="<%= label_for_question_type(question_type) %>" />
<% elsif question_type.entry_type == "numerical_text_box" %>
  <%
    if question[:answers].any?{|answer| answer[:numerical_answer_type] == 'precision_answer' }
      answer_type_class = 'precision_question_input'
    else
      answer_type_class = 'numerical_question_input'
    end
  %>
  <input
    type="text"
    name="question_<%= hash_get(question, :id) %>"
    value="<%= value %>"
    class="question_input <%= answer_type_class %>"
    autocomplete='off'
    <%= 'readonly="readonly"' unless editable %>
    aria-label="<%= label_for_question_type(question_type) %>"
  />
<% elsif question_type.entry_type == "textarea" %>
  <% unless @context.feature_enabled?(:rce_enhancements) %>
    <div class="rce_links">
      <a href="#" class="toggle_question_content_views_link"><%= t "HTML Editor" %></a>
      <a href="#" class="toggle_question_content_views_link" style="display:none;"><%= t "Rich Content Editor" %></a>
    </div>
    <div class="clearfix"></div>
  <% end %>
  <textarea name="question_<%= hash_get(question, :id) %>" class="question_input" autocomplete='off' <%= 'readonly="readonly"' unless editable %>><%= value %></textarea>
<% elsif question_type.entry_type == "file" %>
  <% if !editable%>
    <% attachment = @attachments[user_answer[:attachment_ids].try(:first).to_i] %>
      <% if attachment %>
        <a class="icon-download" href="<%= file_download_url(attachment) %>">
          <%= attachment.display_name %>
        </a>
      <% end %>
  <% else %>
    <div class="control-group">
      <div class=controls>
        <label class="control-label upload-label" for=file>
          <%= t 'upload', 'Upload' %>
        </label>
        <%# this is here so FileUploadQuestionView has a place to hook into %>
        <div class="content-box border border-trbl file-upload-box">
        </div>
      </div>
    </div>
    <input type="file" name="" value="<%attachment_id_for(question) %>"
    class="question_input file-upload hidden" <%= 'readonly="readonly"' unless editable %>/>
    <input type="hidden" class="attachment-id question_input"
    name="question_<%= question[:id] %>[]"
    value="<%= attachment_id_for(question) %>"/>
  <% end %>
<% end %>

</div>
