{% load wagtailcore_tags core_tags gem_tags wagtailimages_tags static forms_personalise_extras %}
{% wagtail_site as current_site %}
{% block content %}
{% filter_forms_by_segments forms request as filtered_forms %}
{% for item in filtered_forms %}
  {% with form_page=item.molo_form_page form=item.form %}
    {% if form_page.your_words_competition %}
      <div class="your-words your-words{{ self.get_effective_extra_style_hints }}">
        <div class="section-title">
          <h2>{% trans "Share your story" %}</h2>
        </div>
        <h3>{{ form_page.title }}</h3>
        <p>{{ form_page.homepage_introduction }}</p>
        <img src="{% static 'img/Pencil.png' %}" />
        {% if user.is_authenticated and user.is_active or request.is_preview or form_page.allow_anonymous_submissions %}
          <a href="{% pageurl form_page.specific %}" class="button call-to-action__button call-to-action__button--primary">
            {% if form_page.homepage_button_text %}
              {{form_page.homepage_button_text}}
            {% else %}
              {% trans "Write your story" %}
            {% endif %}
          </a>
        {% else %}
          <a href="{{ LOGIN_URL }}?next={{request.path}}" class="button call-to-action__button call-to-action__button--primary">
            {% trans "Log in to Enter" %}
          </a>
        {% endif %}
      </div>
    {% elif form_page.display_form_directly %}
      <div class="polls gem-polls">
        <div class="section-title">
          <h4 class="poll__title list-header">{% trans "What's your opinion?" %}</h4>
        </div>
        <div class="list-inline">
          <h2 class="poll__question-title">{{ form_page.title }}</h2>
          {% if form %}
            {% include "forms/form.html" with formtype="poll" formtypeClass="polls"  %}
          {% else %}
            <p class="error error--poll">{% trans 'You have already completed this poll.' %}</p>
            {% if request.path == "/" %}
              <a href="{% url 'molo.forms:success' form_page.slug %}" class="button call-to-action__button call-to-action__button--primary">
                {% trans "Show Results" %}
              </a>
            {% else %}
              <a href="{{current_site.root_page.specific.url}}" class="button call-to-action__nav-item call-to-action__nav-item--back-home">
              {% trans "Back home" %}</a>
            {% endif %}
          {% endif %}
        </div>
      </div>
    {% elif form_page.article_form_only %}
      <div class="surveys surveys__tout surveys{{self.get_effective_extra_style_hints}}">
        <div class="section-title">
          <h2>Question</h2>
        </div>
        <div class="surveys__item">
          <h3>{{ form_page.title }}</h3>
          <p>{{ form_page.homepage_introduction }}</p>
          {% if user.is_authenticated and user.is_active or request.is_preview or form_page.allow_anonymous_submissions %}
            <a href="{% pageurl form_page.specific %}" class="button call-to-action__button call-to-action__button--primary">
              {% if form_page.homepage_button_text %}
                {{form_page.homepage_button_text}}
              {% else %}
                {% trans "Start Poll" %}
              {% endif %}
            </a>
          {% else %}
            <a href="{{ LOGIN_URL }}?next={{request.path}}" class="button call-to-action__button call-to-action__button--primary">
              {% trans "Log in to Enter" %}
            </a>
          {% endif %}
        </div>
      </div>
    {% else %}
      <div class="surveys surveys__tout surveys{{self.get_effective_extra_style_hints}}">
        <div class="section-title">
          <h2>Take the Survey</h2>
        </div>
        <div class="surveys__item">
          <h3>{{ form_page.title }}</h3>
          <p>{{ form_page.homepage_introduction }}</p>
          {% if user.is_authenticated and user.is_active or request.is_preview or form_page.allow_anonymous_submissions %}
            <a href="{% pageurl form_page.specific %}" class="button call-to-action__button call-to-action__button--primary">
              {% if form_page.homepage_button_text %}
                {{form_page.homepage_button_text}}
              {% else %}
                {% trans "Start Survey" %}
              {% endif %}
            </a>
          {% else %}
            <a href="{{ LOGIN_URL }}?next={{request.path}}" class="button call-to-action__button call-to-action__button--primary">
              {% trans "Log in to Enter" %}
            </a>
          {% endif %}
        </div>
      </div>
    {% endif %}
  {% endwith %}
{% endfor %}
{% endblock %}
