{%- extends 'base_templates/page_base_half_wider.html' %}
{%- from "base_templates/form_macros.html" import render_addon_field, render_field, render_select_field, render_submit_field, myrender_hidden_field, render_file_field with context %}
{%- block top %}
{%- endblock %}
{%- block content %}
        <div class="row">
          <div class="col-sm-9 col-md-7 col-lg-7 col-xl-7">
            {%- if description %}
            <div class="card">
              <div class="card-body">
                {{ description }}
              </div>
            </div>
            {%- endif %}
            <ul class="nav nav-pills">
              <li class="nav-item">
                <a class="nav-link" title="{{ word('Create a new package') }}" href="{{ url_for('playground_packages', project=current_project, new='1') }}"><i class="fas fa-plus-circle" aria-hidden="true"></i>&nbsp;&nbsp;{{ word('Add') }}</a>
              </li>
              <li class="nav-item dropdown">
                <a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false" title="{{ word('Edit another package')}}">
                  <i class="fas fa-briefcase" 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_packages', 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">
                <a tabindex="5" class="nav-link" id="uploadlink" style="cursor: pointer" title="{{ word('Upload a package ZIP file to the Playground') }}">
                  <form action="{{ url_for('playground_packages', 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>
              <li class="nav-item">
                <a class="nav-link" tabindex="7" id="daPull" href="{{ url_for('pull_playground_package', project=current_project, github=github_url, branch=branch) if github_url else url_for('pull_playground_package', project=current_project, pypi=pypi_package_name) if pypi_package_name else url_for('pull_playground_package', project=current_project) }}" title="{{ word('Pull a package from GitHub or PyPI into the Playground') }}">
                  <i class="fas fa-cloud-download-alt" aria-hidden="true"></i>&nbsp;&nbsp;{{ word("Pull") }}
                </a>
              </li>
            </ul>
          </div>
        </div>
        <form action="{{ url_for('playground_packages', project=current_project) }}" method="POST" class="form" role="form" id="form" autocomplete="off">
          <div class="row">
            <div class="col-sm-9 col-md-7 col-lg-7 col-xl-7">
              {{ form.hidden_tag() }}
              {{ myrender_hidden_field(form.original_file_name, value=current_file) }}
              {{ render_field(form.file_name) }}
              {{ render_field(form.version) }}
              {{ render_field(form.license) }}
              {{ render_field(form.author_name) }}
              {{ render_field(form.author_email) }}
              {{ render_field(form.description) }}
              {{ render_field(form.url) }}
              <h2>{{ form.dependencies.label }}</h2>
              <div class="da-form-group">
                <label class="form-label" for="{{ form.dependencies.id }}">{{ word("Select zero or more packages") }}</label>
                <select multiple size="{% if package_names.__len__() < 10 %}{{ package_names.__len__() }}{% else %}10{% endif %}" class="form-control" name="{{ form.dependencies.id }}" id="{{ form.dependencies.id }}">
                  {%- for package in package_names %}
                  <option value="{{ package }}"{% if form.dependencies.data and package in form.dependencies.data %} selected{% endif %}>{{ package }}</option>
                  {%- endfor %}
                </select>
              </div>
              {%- for sec in ['playground', 'playgroundtemplate', 'playgroundstatic', 'playgroundsources', 'playgroundmodules'] %}
              <h2>{{ section_field[sec].label }}</h2>
              <div class="da-form-group">
                <label class="form-label" for="{{ section_field[sec].id }}">{{ word("Select zero or more files") }}</label>
                <select multiple size="{% if file_list[sec].__len__() < 10 %}{{ file_list[sec].__len__() }}{% else %}10{% endif %}" class="form-control" name="{{ section_field[sec].id }}" id="{{ section_field[sec].id }}">
                  {%- for file in file_list[sec] %}
                  <option value="{{ file }}"{% if section_field[sec].data and file in section_field[sec].data %} selected{% endif %}>{{ file }}</option>
                  {%- endfor %}
                </select>
              </div>
              {%- endfor %}
            </div>
          </div>
          <div class="row">
            <div class="col-sm-8 col-md-8 col-lg-8 col-xl-8">
              <h2>{{ form.readme.label }}</h2>
              <div class="da-form-group">
                <label class="form-label" for="{{ form.readme.id }}">{{ word("The README.md file for the package") }}</label>
                <textarea rows="24" cols="80" id="{{ form.readme.id }}" name="{{ form.readme.id }}">{{ form.readme.data }}</textarea>
              </div>
              {%- if pypi_message %}
              <div class="card mb-3">
                <div class="card-body">
                  {{ pypi_message|safe }}
                </div>
              </div>
              {%- endif %}
              {%- if github_message %}
              <div class="card mb-3">
                <div class="card-body">
                  {{ github_message|safe }}
                </div>
              </div>
              {%- endif %}
              {%- if can_publish_to_github %}
              <div id="commit_message_div" style="display:none">
                <div id="github_branch_div">
                  {{ render_select_field(form.github_branch) }}
                  <div id="new_branch_div" style="display:none">
                    {{ render_field(form.github_branch_new) }}
                  </div>
                </div>
                {{ render_field(form.commit_message) }}
                {%- if can_publish_to_pypi %}
                <div class="form-check">
                    {{ form.pypi_also(type='checkbox', class='form-check-input') }}
                    <label class="form-check-label" for="{{ form.pypi_also.id }}">{{ form.pypi_also.label }}</label>
                </div>
                {%- endif %}
                <div class="form-check">
                    {{ form.install_also(type='checkbox', class='form-check-input') }}
                    <label class="form-check-label" for="{{ form.install_also.id }}">{{ form.install_also.label }}</label>
                </div>
              </div>
              {%- endif %}
              {%- if can_publish_to_pypi %}
              <div id="pypi_message_div" style="display:none">
                <p>{{ word("Press the Publish button to publish the package on PyPI.") }}</p>
                <div class="form-check">
                    {{ form.install_also(type='checkbox', class='form-check-input') }}
                    <label class="form-check-label" for="{{ form.install_also.id }}">{{ form.install_also.label }}</label>
                </div>
              </div>
              {%- endif %}
              <div class="form-actions mt-3">
                {{ render_submit_field(form.submit, class="btn " + config['BUTTON_STYLE'] + "primary " + config['BUTTON_CLASS'], title=word('Save your changes to the package information')) }}
                {%- if current_file != '' %}
                {{ render_submit_field(form.install, class="btn " + config['BUTTON_STYLE'] + "success " + config['BUTTON_CLASS'], title=word('Install package on this server')) }}
                {%- if can_publish_to_pypi %}
                {{ render_submit_field(form.pypi, id="daPyPI", class="btn " + config['BUTTON_STYLE'] + "warning " + config['BUTTON_CLASS'], title=word('Publish on PyPI')) }}
                {{ render_submit_field(form.cancel, id="daCancelPyPI", class="btn " + config['BUTTON_STYLE'] + "secondary " + config['BUTTON_CLASS'], style="display:none") }}
                {%- endif %}
                {%- if can_publish_to_github %}
                {{ render_submit_field(form.github, id="daGitHub", class="btn " + config['BUTTON_STYLE'] + "warning " + config['BUTTON_CLASS'], title=word('Push a commit to GitHub')) }}
                {{ render_submit_field(form.cancel, id="daCancelGitHub", class="btn " + config['BUTTON_STYLE'] + "secondary " + config['BUTTON_CLASS'], style="display:none") }}
                {%- endif %}
                <a class="btn {{ config['BUTTON_STYLE'] }}info {{ config['BUTTON_CLASS'] }}" href="{{ url_for('create_playground_package', project=current_project, package=current_file) }}" title="{{ word('Download the current package') }}">{{ word('Download') }}</a>
                {{ render_submit_field(form.delete, id="daDelete", class="btn " + config['BUTTON_STYLE'] + "danger " + config['BUTTON_CLASS'], title=word('Delete this package from the Playground')) }}
                {%- else %}
                <a class="btn {{ config['BUTTON_STYLE'] }}secondary {{ config['BUTTON_CLASS'] }}" href="{{ url_for('playground_packages', project=current_project) }}">{{ word('Cancel') }}</a>
                {%- endif %}
              </div>
            </div>
          </div>
        </form>
        {%- if after_text %}
        <p>{{ after_text }}</p>
        {%- endif %}
{%- endblock %}
{%- block bottom %}
      <div class="mt-2"><a href="{{ url_for('playground_page', project=current_project) }}" class="btn {{ config['BUTTON_STYLE'] }}secondary btn-md"><i class="fas fa-chevron-left"></i>&nbsp;{{ word("Back to Playground") }}</a></div>
{%- endblock %}
