<%!
  import json
  from django.utils.translation import ugettext as _
  from microsite_configuration import microsite
%>
<%inherit file="../main.html" />

<%namespace name='static' file='../static_content.html'/>

<%block name="header_extras">
  % if settings.FEATURES.get('ENABLE_COURSE_DISCOVERY'):
  % for template_name in ["result_item", "filter_bar", "filter", "search_facets_list", "search_facets_section", "search_facet", "more_less_links"]:
  <script type="text/template" id="${template_name}-tpl">
      <%static:include path="discovery/${template_name}.underscore" />
  </script>
  % endfor
  <script type="text/javascript">;(function (define) {{
      define('course_discovery_meanings', function() {{
          'use strict';
          return ${json.dumps(course_discovery_meanings)};
        }});
      }})(define || RequireJS.define);
  </script>
  % endif
</%block>

<%block name="js_extra">
  % if settings.FEATURES.get('ENABLE_COURSE_DISCOVERY'):
  <%static:js group='discovery'/>
  % endif
</%block>

<%block name="pagetitle">${_("Courses")}</%block>
<%
  platform_name = microsite.get_value('platform_name', settings.PLATFORM_NAME)
  course_discovery_enabled = settings.FEATURES.get('ENABLE_COURSE_DISCOVERY')
  if self.stanford_theme_enabled():
    course_index_overlay_text = _("Explore free courses from {university_name}.").format(university_name="Stanford University")
    logo_file = static.url('themes/stanford/images/seal.png')
    logo_alt_text = "Stanford Seal Logo"

  else:
    course_index_overlay_text = microsite.get_value('course_index_overlay_text', _("Explore courses from {platform_name}.").format(platform_name=platform_name))

    if settings.FEATURES.get('IS_EDX_DOMAIN', False):
      # For some reason, `static.url('images/edx-theme/edx-logo-bw.png')` breaks template rendering.
      default_image_url = settings.STATIC_URL + 'images/edx-theme/edx-logo-bw.png'
    else:
      default_image_url = settings.STATIC_URL + 'images/default-theme/logo-large.png'

    logo_file = microsite.get_value(
      'course_index_overlay_logo_file', default_image_url
    )

    logo_alt_text = _("{platform_name} Logo").format(platform_name=platform_name)
%>

<section class="find-courses">

  <header class="search">
    <div class="inner-wrapper main-search">
      <hgroup>
        <div class="logo">
          <img src="${logo_file}" alt="${logo_alt_text}" />
        </div>
        <h2>${course_index_overlay_text}</h2>
      </hgroup>
    </div>
  </header>

  <section class="courses-container">

    % if course_discovery_enabled:
    <div id="discovery-form" role="search" aria-label="course">
      <form>
        <input class="discovery-input" placeholder="${_('Search for a course')}" type="text"/><!-- removes spacing
        --><button type="submit" class="button postfix discovery-submit" aria-label="${_('Search')}">
          <i class="icon fa fa-search" aria-hidden="true"></i>
        </button>
      </form>
      <div id="discovery-message"></div>
      <div aria-live="polite" aria-relevant="all">
        <div id="loading-indicator" class="hidden">
          <i class="icon fa fa-spinner fa-spin"></i> ${_('Loading')}
        </div>
      </div>
    </div>

    <div id="filter-bar" class="filters hide-phone">
    </div>
    % endif

    <section class="courses${'' if course_discovery_enabled else ' no-course-discovery'}">
      <ul class="courses-listing">
        %for course in courses:
        <li class="courses-listing-item">
          <%include file="../course.html" args="course=course" />
        </li>
        %endfor
      </ul>
    </section>


    % if course_discovery_enabled:
    <aside aria-label="${_('Refine your search')}" class="search-facets phone-menu">
    </aside>
    % endif

  </section>
</section>
