{% extends 'base_templates/flask_two_col_base.html' %}
{% block content %}
{%- from "base_templates/form_macros.html" import render_addon_field, render_submit_field, myrender_hidden_field, render_file_field with context %}
<ul class="nav nav-pills mt-1">
  <li class="nav-item">
    <a class="nav-link" tabindex="1" title="{{ word('Create a new interview') }}" href="{{ url_for('playground_page', 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">
    <a class="nav-link" tabindex="2" title="{{ word('Create an interview with the wizard') }}" href="{{ url_for('index', i='docassemble.webapp:data/questions/wizard-template.yml', project=current_project) }}"><i class="fas fa-magic" aria-hidden="true"></i>&nbsp;&nbsp;{{ word('Wizard') }}</a>
  </li>
  <li class="nav-item dropdown">
    <a tabindex="3" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false" title="{{ word('Items in the Playground other than interviews') }}">
      <i class="fas fa-folder-open" aria-hidden="true"></i>&nbsp;&nbsp;{{ word('Folders') }}
    </a>
    <div class="dropdown-menu">
      <a class="dropdown-item" href="{{ url_for('playground_packages', project=current_project) }}"><i class="fas fa-briefcase fa-fw" aria-hidden="true"></i>&nbsp;{{ word('Packages') }}</a>
      <a class="dropdown-item" href="{{ url_for('playground_files', project=current_project, section='template') }}"><i class="fas fa-file fa-fw" aria-hidden="true"></i>&nbsp;{{ word('Templates') }}</a>
      <a class="dropdown-item" href="{{ url_for('playground_files', project=current_project, section='static') }}"><i class="fas fa-image fa-fw" aria-hidden="true"></i>&nbsp;{{ word('Static files') }}</a>
      <a class="dropdown-item" href="{{ url_for('playground_files', project=current_project, section='sources') }}"><i class="fas fa-database fa-fw" aria-hidden="true"></i>&nbsp;{{ word('Sources') }}</a>
      <a class="dropdown-item" href="{{ url_for('playground_files', project=current_project, section='modules') }}"><i class="fas fa-cogs fa-fw" aria-hidden="true"></i>&nbsp;{{ word('Modules') }}</a>
    </div>
  </li>
  <li role="presentation" class="nav-item dropdown">
    <a tabindex="4" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false" title="{{ word('Edit another interview')}}">
      <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 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_page', 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>
  <li class="nav-item" role="presentation">
    <a class="nav-link" tabindex="5" id="uploadlink" style="cursor: pointer" title="{{ word('Upload a YAML file to the Playground') }}">
      <form action="{{ url_for('playground_page', project=current_project) }}" method="POST" class="form" role="form" id="fileform" enctype="multipart/form-data">
        {{ fileform.hidden_tag() }}
        <label id="uploadlabel" for="uploadfile" style="position: inline; font-weight: normal; cursor: pointer; margin: 0">
          <i class="fas fa-upload" aria-hidden="true"></i>&nbsp;&nbsp;{{ word("Upload") }}
        </label>
        <div style="width: 0px; height: 0px; overflow: hidden">
          <input type="file" name="uploadfile" id="uploadfile"/>
        </div>
      </form>
    </a>
  </li>
  {%- if use_gd %}
  <li class="nav-item" role="presentation">
    <a class="nav-link" tabindex="7" href="{{ url_for('sync_with_google_drive', project=current_project, next=url_for('playground_page', project=current_project)) }}" title="{{ word('Sync with Google Drive') }}">
      <i class="fab fa-google-drive" aria-hidden="true"></i>&nbsp;&nbsp;{{ word('Sync') }}
    </a>
  </li>
  {%- endif %}
  {%- if use_od %}
  <li class="nav-item" role="presentation">
    <a class="nav-link" tabindex="7" href="{{ url_for('sync_with_onedrive', project=current_project, next=url_for('playground_page', project=current_project)) }}" title="{{ word('Sync with OneDrive') }}">
      <i class="fab fa-windows" aria-hidden="true"></i>&nbsp;&nbsp;{{ word('Sync') }}
    </a>
  </li>
  {%- endif %}
</ul>
<form action="{{ url_for('playground_page', project=current_project) }}" method="POST" class="form pgform" role="form" id="form" autocomplete="off">
  {{ form.hidden_tag() }}
  {%- if is_new != 'False' %}
  {{ myrender_hidden_field(form.status, value='new') }}
  {%- else %}
  {{ myrender_hidden_field(form.status, value='existing') }}
  {%- endif %}
  {{ myrender_hidden_field(form.original_playground_name, value=current_file) }}
  <div class="row mb-1 mt-1">
    <div class="col-lg-6">
      {{ render_addon_field(form.playground_name, tabindex=20) }}
    </div>        
    <div class="col-lg-6">
      {{ render_addon_field(form.search_term, tabindex=80, autocomplete="off", extra='<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>
  </div>
  <textarea rows="34" cols="80" id="playground_content" name="playground_content" tabindex="70">{{ content }}</textarea>
  <div class="form-actions mt-2 ml-1">
    {{ render_submit_field(form.submit, class="ms-1 btn " + config['BUTTON_STYLE'] + "primary " + config['BUTTON_CLASS'] + " dasubmitbutton", tabindex="90") }}
    {% if is_new == 'False' %}<a tabindex="100" id="daRun" target="_blank" href="{{ url_for('playground_redirect', project=current_project) }}" class="btn {{ config['BUTTON_STYLE'] }}warning {{ config['BUTTON_CLASS'] }} dasubmitbutton" >{{ word("Save and Run") }}</a>
    {%- if use_gd %}
    <a tabindex="101" id="daRunSyncGD" target="_blank" href="{{ url_for('playground_poll') }}" class="btn {{ config['BUTTON_STYLE'] }}warning {{ config['BUTTON_CLASS'] }} dasubmitbutton" ><i class="fab fa-google-drive" aria-hidden="true"></i>&nbsp;&nbsp;{{ word("Sync and Run") }}</a>
    {%- endif %}
    {%- if use_od %}
    <a tabindex="101" id="daRunSyncOD" target="_blank" href="{{ url_for('playground_poll') }}" class="btn {{ config['BUTTON_STYLE'] }}warning {{ config['BUTTON_CLASS'] }} dasubmitbutton" ><i class="fab fa-windows" aria-hidden="true"></i>&nbsp;&nbsp;{{ word("Sync and Run") }}</a>
    {%- endif %}

    <a tabindex="102" target="_blank" href="{{ url_for('playground_download', current_project=current_project, userid=userid, filename=current_file) }}" class="btn {{ config['BUTTON_STYLE'] }}info {{ config['BUTTON_CLASS'] }} dasubmitbutton" >{{ word("Download") }}</a>
    
    {{ render_submit_field(form.delete, id='daDelete', class="btn " + config['BUTTON_STYLE'] + "danger " + config['BUTTON_CLASS'] + " dasubmitbutton", tabindex="110") }}

    {% if interview_path %}
    <a tabindex="120" title="Right-click to copy link" id="share-link" class="dabadge btn btn-secondary da-example-share" target="_blank" href="{{ url_for('index', i=interview_path) }}"><i class="fas fa-link"></i>&nbsp;&nbsp;{{ word('Share') }}</a>
    {% endif %}
    {% endif %}
  </div>
</form>
{%- endblock %}
{% block rightside %}
            <div id="playgroundbox" class="card bg-light playgroundbox mt-1">
              <div class="card-header">{{ word('Names 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="dabadge btn btn-primary da-larger-badge dasubmitbutton" target="_blank" id="daRunButton">{{ word('Run') }}</a>&nbsp;<a title="{{ word('Show report of names and associated questions') }}" class="dabadge btn btn-secondary da-larger-badge" data-bs-toggle="modal" href="" id="daVariablesReportLauncher" data-bs-target="#daVariablesReport"><i class="fas fa-list"></i></a></div>
              <div class="card-body" id="daplaygroundcard">
                <table id="daplaygroundtable" class="daplaygroundtable">{{ variables_html }}
                </table>
              </div>
            </div>
{%- endblock %}
{% block bottompart %}
{{ example_html }}
<div class="modal" id="daVariablesReport" tabindex="-1" role="dialog">
  <div class="modal-dialog modal-xl" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title">{{ word("Names and questions") }}</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="{{ word("Close") }}"></button>
      </div>
      <div class="modal-body">
        <p>{{ word("Loading . . .") }}</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">{{ word("Close") }}</button>
      </div>
    </div>
  </div>
</div>
{%- endblock %}
