{%- extends 'base_templates/page_base_half_pgfiles.html' %}
{%- from "base_templates/form_macros.html" import render_addon_field, render_field, render_submit_field, myrender_hidden_field, render_file_field with context %}
{%- block top %}
{%- endblock %}
{%- block content %}
{%- if description %}
          <div class="card">
            <div class="card-body">
              {{ description }}
            </div>
          </div>
          {%- endif %}
          {%- if upload_header %}
          <div class="mt-3">
            <h3>{{ upload_header }}</h3>
          </div>

          <form action="{{ url_for('playground_files', project=current_project) }}" method="POST" class="form" role="form" enctype="multipart/form-data">
            {{ form.hidden_tag() }}
            {{ myrender_hidden_field(form.purpose, value='upload') }}
            {{ myrender_hidden_field(form.section, value=section) }}
            {{ render_file_field(form.uploadfile, tabindex=60, multiple=True) }}
            <div class="form-actions">
              {{ render_submit_field(form.submit, tabindex=565, id="dauploadbutton") }}
            </div>
          </form>
          <div class="mt-3">
            {%- if use_gd %}
            <div class="daonright">
              <a tabindex="15" title="{{ word('Sync with Google Drive') }}" class="btn {{ config['BUTTON_STYLE'] }}success mb-2" href="{{ url_for('sync_with_google_drive', project=current_project, next=url_for('playground_files', project=current_project, section=section)) }}"><i class="fab fa-google-drive"></i>&nbsp;{{ word('Sync') }}</a>
            </div>
            {%- endif %}
            {%- if use_od %}
            <div class="daonright">
              <a tabindex="15" title="{{ word('Sync with OneDrive') }}" class="btn {{ config['BUTTON_STYLE'] }}success mb-2" href="{{ url_for('sync_with_onedrive', project=current_project, next=url_for('playground_files', project=current_project, section=section)) }}"><i class="fab fa-windows"></i>&nbsp;{{ word('Sync') }}</a>
            </div>
            {%- endif %}            
            <h3>{{ list_header }}</h3>
          </div>
          {%- if files %}
          <table class="table table-striped mt-2">
            <thead>
              <tr>
                <th>{{ word("File name") }}</th>
                <th style="text-align:right;">{{ word("Action") }}</th>
              </tr>
            </thead>
            <tbody>
            {%- for file in files %}
              <tr>
                <td><a tabindex="20" target="_blank" href="{{ url_for('playground_' + section, userid=userid, filename=file, current_project=current_project) }}">{{ file }}</a></td>
                <td style="text-align: right; white-space: nowrap">{% if file in editable_file_listing %}<a tabindex="20" class="btn {{ config['BUTTON_STYLE'] }}success btn-sm mb-1" href="{{ url_for('playground_files', section=section, file=file, project=current_project) }}">{{ word('Edit') }}</a> {% endif %}{% if file in trainable_files %}<a tabindex="20" class="btn {{ config['BUTTON_STYLE'] }}success btn-sm mb-1" href="{{ url_for('train', package=playground_package, file=trainable_files[file]) }}">{{ word('Train') }}</a> {% endif %}{% if file in convertible_files %}<a tabindex="20" class="btn {{ config['BUTTON_STYLE'] }}info btn-sm mb-1" href="{{ url_for('playground_files', section=section, convert=file, project=current_project) }}">{{ word('Convert to .md') }}</a> {% endif %}<a tabindex="20" class="btn {{ config['BUTTON_STYLE'] }}danger btn-sm mb-1" href="{{ url_for('playground_files', section=section, delete=file, project=current_project) }}">{{ word('Delete') }}</a></td>
              </tr>
            {% endfor %}
            </tbody>
          </table>
          {%- else %}
          <p><em>{{ word("No files have been uploaded yet.") }}</em></p>
          {%- endif %}
          {%- endif %}
          {%- if edit_header %}
          <h3>{{ edit_header }}</h3>
          {%- endif %}
          {%- if lowerdescription %}
          <div class="card">
            <div class="card-body">
              {{ lowerdescription }}
            </div>
          </div>
          {%- endif %}
{%- endblock %}
{%- block below %}
{%- if active_file %}
          <div class="col-md-8 pgmain">
{%- else %}
          <div class="col-md-10 pgmain">
{%- endif %}
            <ul id="editnav" class="nav nav-pills mt-1">
              <li class="nav-item">
                <a tabindex="571" class="nav-link" title="{{ word('Create a new file') }}" href="{{ url_for('playground_files', section=section, new='1', project=current_project) }}"><i class="fas fa-plus-circle" aria-hidden="true"></i>&nbsp;&nbsp;{{ word('Add') }}</a>
              </li>
              <li class="nav-item dropdown">
                <a tabindex="572" class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false" title="{{ word('Edit another file')}}">
                  <i class="fas fa-file" aria-hidden="true"></i>&nbsp;&nbsp;{% if current_file == '' %}{{ word("(New file)") }}{% else %}{{ current_file }}{% endif %}
                </a>
                <div class="dropdown-menu daheightlim">
                  {%- if any_files %}
                  {%- for file in editable_files %}
                  {%- if file['name'] == current_file %}
                  <a class="dropdown-item active" href="#"><i class="fas fa-file fa-fw" aria-hidden="true"></i>&nbsp;{{ file['name'] }}</a>
                  {%- else %}
                  <a class="dropdown-item" href="{{ url_for('playground_files', section=section, file=file['name'], project=current_project) }}"><span style="opacity: {{ file['opacity'] }}"><i class="fas fa-file fa-fw" aria-hidden="true"></i></span>&nbsp;{{ file['name'] }}</a>
                  {%- endif %}
                  {%- endfor %}
                  {%- else %}
                  <a class="dropdown-item active" href="#"><i class="fas fa-file fa-fw" aria-hidden="true"></i>&nbsp;{% if current_file == '' %}{{ word("(New file)") }}{% else %}{{ current_file }}{% endif %}</a>
                  {%- endif %}
                </div>
              </li>
            </ul>

            <form action="{{ url_for('playground_files', project=current_project) }}" method="POST" class="form pgform" role="form" id="formtwo" autocomplete="off">
              {{ formtwo.hidden_tag() }}
              {{ myrender_hidden_field(formtwo.purpose, value='edit') }}
              {{ myrender_hidden_field(formtwo.section, value=section) }}
              {{ myrender_hidden_field(formtwo.original_file_name, value=current_file) }}
              <div class="row mb-1 mt-1">
                <div class="col-lg-6">
                  {{ render_addon_field(formtwo.file_name, tabindex=579) }}
                </div>
                <div class="col-lg-6">
                  {{ render_addon_field(formtwo.search_term, tabindex=590, autocomplete="off", extra='<div class="input-group-append"><button title="' + word('Previous result') + '" class="btn btn-outline-secondary da-no-outline pointer" id="daSearchPrevious"><i class="fas fa-chevron-left"></i></button><button title="' + word('Next result') + '" class="btn btn-outline-secondary da-no-outline pointer" id="daSearchNext"><i class="fas fa-chevron-right"></i></button></div>', extra_class='pull-right') }}
                </div>
              </div>
              <textarea rows="24" cols="80" id="file_content" name="file_content" tabindex="580">{{ content }}</textarea>
              <div class="form-actions mt-2 ml-1">
                {{ render_submit_field(formtwo.submit, tabindex=600, class="btn " + config['BUTTON_STYLE'] + "primary " + config['BUTTON_CLASS'], data={'disable-button': 0}) }}
                {% if is_new == 'False' %}<a tabindex="605" class="btn {{ config['BUTTON_STYLE'] }}info {{ config['BUTTON_CLASS'] }}" href="{{ url_for('playground_' + section, userid=userid, filename=current_file, current_project=current_project, attach='1') }}">{{ word("Download") }}</a> <a tabindex="610" class="btn {{ config['BUTTON_STYLE'] }}danger {{ config['BUTTON_CLASS'] }}" href="{{ url_for('playground_files', section=section, delete=current_file, project=current_project) }}">{{ word('Delete') }}</a>{% endif %}
              </div>
            </form>
            {%- if after_text %}
            <p>{{ after_text }}</p>
            {%- endif %}
          </div>
{%- if active_file %}
          <div class="col-md-4 pgright">
            <div id="playgroundbox" class="card bg-light playgroundbox">
              <div class="card-header">{{ word('Variables, etc. from') }}&nbsp;<span class="select-wrapper"><select tabindex="130" id="daVariables" class="playground-select">{% for file in pulldown_files %}<option {% if file == active_file %}selected {% endif %}value="{{ file }}">{{ file }}</option>{% endfor %}</select></span>&nbsp;<a class="badge badge-primary da-larger-badge" target="_blank" id="daRunButton">{{ word('Run') }}</a></h3>
              </div>
              <div class="card-body" id="daplaygroundcard">
                <table id="daplaygroundtable" class="daplaygroundtable">
                </table>
              </div>
            </div>
          </div>
{%- endif %}
{%- endblock %}
{%- block bottom %}
      <div class="mt-2"><p><a tabindex="620" href="{{ url_for('playground_page', project=current_project) }}" class="btn {{ config['BUTTON_STYLE'] }}info"><i class="fas fa-caret-left"></i>&nbsp;{{ word("Back to Playground") }}</a></p></div>
{%- endblock %}
