{# vim: set ts=2 et sts=2 sw=2: #}
{% extends "questions/includes/question_editing_frame.html" %}
{% set title = _('Ask a Question') %}
{% set crumbs = [(url('questions.questions'), _('Forum')),
                 (None, _('Ask a New Question'))] %}

{% block headline %}{{ _('Ask a New Question') }}{% endblock %}

{% block product %}
  {% if not current_product %}
    <h2>{{ _('Which Firefox product would you like to post a question about?') }}</h2>
    <ul class="select-one">
      {% for key, product in products.iteritems() %}
        <li>
          <a href="{{ url('questions.new_question')|urlparams(product=key) }}">{{ product.name }}</a>
        </li>
      {% endfor %}
    </ul>
  {% else %}
    {{ super() }}
  {% endif %}
{% endblock %}

{% block product_changer %}
  {% if current_product %}
    <a href="{{ url('questions.new_question') }}">{{ _('change') }}</a>
  {% endif %}
{% endblock %}


{% block category %}
  {% if current_product and not current_category and current_product.categories %}
    <h2>{{ _('Which of these categories best describes your problem?') }}</h2>
    <ul class="select-one">
      {% for key, category in current_product.categories.iteritems() %}
        <li>
          <a href="{{ url('questions.new_question')|urlparams(product=current_product.key, category=key) }}">{{ category.name }}</a>
        </li>
      {% endfor %}
    </ul>
  {% else %}
    {{ super() }}
  {% endif %}
{% endblock %}

{% block category_changer %}
  {% if not (current_product and not current_category) %}
    <a href="{{ url('questions.new_question')|urlparams(product=current_product.key) }}">{{ _('change') }}</a>
  {% endif %}
{% endblock %}

{% block articles_and_search_results %}
  {% set form_header_set = False %}
  {% if (current_articles or current_html) and not search_results and not form %}
    {% if current_html %}
      <h2>{{ current_html|safe }}</h2>
    {% else %}
      <h2>{{ _('We have lots of helpful articles on <mark>{category}</mark> and hundreds of questions in our database. Try one of the following:')|fe(category=current_category.name) }}</h2>
    {% endif %}
    {% if current_articles %}
      <ul class="articles">
        {% for article in current_articles %}
          <li>
            <a href="{{ article.url }}" target="_blank">{{ article.title }}</a>
          </li>
        {% endfor %}
      </ul>
    {% endif %}
    {% if not form and not deadend %}
      {% set form_header_set = True %}
      <h2>{{ _('or, summarize your question in a sentence:') }}</h2>
    {% endif %}
  {% endif %}

  {% if current_category and ((current_articles or search_results or current_html)
        or not (current_articles and search_results and current_html))
        and not form and not deadend %}
    {% if not form_header_set %}
      <h2>{{ _('Summarize your question in a sentence:') }}</h2>
    {% endif %}
    <form id="ask-search-form" class="search" action="{% if settings.SESSION_COOKIE_SECURE %}https://{{ host }}{{ request.get_full_path() }}{% endif %}#ask-search-form" method="get">
      <input type="hidden" name="product" value="{{ current_product.key }}" />
      <input type="hidden" name="category" value="{{ current_category.key }}" />
      <input type="text" class="question" name="search" value="{{ request.GET.search }}" />
      <input type="submit" class="btn btn-important" value="{{ _('Ask this') }}" />
    </form>
  {% endif %}

  {% if tried_search and not form %}
    {% if search_results %}
      <h3>{{ _("We've found some articles and previously answered questions that may solve your issue:") }}</h3>
      <ul class="search-results">
        {% for result in search_results %}
          <li>
            <a href="{{ result['url'] }}">{{ result['title'] }}</a>
            <p>
              {{ result['excerpt_html']|safe }}
            </p>
          </li>
        {% endfor %}
      </ul>
      {% set button_text = _('None of these solve my problem') %}
    {% else %}
      <h3 class="no-results">{{ _('This question has not been asked before.') }}</h3>
      {% set button_text = _('Provide more details') %}
    {% endif %}

    <form action="#question-form" method="get">
      <input type="hidden" name="product" value="{{ current_product.key }}" />
      <input type="hidden" name="category" value="{{ current_category.key }}" />
      <input type="hidden" name="search" value="{{ request.GET.search }}" />
      <input type="hidden" name="showform" value="1" />
      <input type="submit" id="show-form-btn" class="btn" value="{{ button_text }}" />
    </form>
  {% endif %}

{% endblock %}

{% block major_detail_instructions %}
  <h2>{{ _('Fill in the details of your question.') }}</h2>
{% endblock %}

{% block submit_button_value %}{{ _('Post Question') }}{% endblock %}
