{% extends "layout.html" %}
{% block body %}

<p>

<div class=body>
  {% if errors %}
  {% for e in range(errors) %}
  <p>{{message[e]}}</p>
  {% endfor %}
  {% endif %}

 <table cellpadding=2 border=0>
   <tr> <td  style="width: 300px;" >

       {% if  cifdict  %}
       <div class=subtitle> Select a Structure File  </div>

       <table cellpadding=2 border=0>
       {% for cifid, labels in cifdict.items() %}
       <tr class={{ loop.cycle('odd', 'even') }}>
             <td><a href="{{url_for('cifs', cifid=cifid)}}">{{labels[0]}}
                 <br>   &nbsp;  &nbsp; {{ labels[1] }} </a>
             </td>
           </tr>
           {% endfor %}
    </table>

       {% else %}
       <div class=subtitle>

         <a href="{{url_for('upload')}}"> Upload a CIF file </a>
       </div>


     {% endif %}

     </td>

     <td>
       <div class=subtitle> Search the American Mineralogist Crystal
         Structures </div>

  <form action="{{url_for('cifs')}}" method="post">

    <table cellpadding=2 border=0>
      <tr>
        <td><label for="mineral">Mineral Name:</label></td>
        <td><input style="width: 250px;" type="text" id="mineral"
                   name="mineral" value="{{ mineral }}">
        </td><td> (example: hem*) </td>
      </tr>
      <tr>
        <td><label for="elems_in">Include   Elements:</label></td>
        <td><input style="width: 250px;" type="text" id="elems_in"
                   name="elems_in" value="{{ elems_in }}">
        </td><td>(example: O, Fe, Si)</td>
      </tr>
      <tr>
        <td><label for="elems_out">Exclude Elements:</label></td>
        <td><input style="width: 250px;" type="text" id="elems_out"
                   name="elems_out" value="{{ elems_out }}">
        </td><td> </td>
      </tr>
      <tr>
        <td>  <input type="submit" name="search" value="Search for CIFs"></td>
        <td colspan=2>  <input type="checkbox" id="strict" name="strict"
                               {% if strict  %} checked="checked" {% endif %}       >
          <label for="strict">Include only the elements listed</label>
        </td>
      </tr>
    </table>
  </form>
  <hr>

  {% if cifid %}

       <div class=subtitle>  Generate XAS Input File     </div>


    <form action="{{url_for('cifs', cifid=cifid)}}" method="post">

    <table cellpadding=2 border=0>
      <tr>
        <td> <label for="absorbing_atom">Absorbing Atom:</label></td>
        <td>
          <select name="absorbing_atom" id="absorbing_atom"
                  style="width: 100px;">
            {% for elem in atoms %}
            <option value="{{elem}}" {% if elem == absorber %} selected {% endif %}> {{elem}}</option>
            {% endfor %}
        </td>
        <td><label for="edge">Edge: </label></td>
        <td>
          <select name="edge" id="edge"  style="width: 100px;">
            {% for ename in edges %}
            <option value="{{ename}}" {% if ename == edge %} selected {% endif %}> {{ename}}</option>
            {% endfor %}
        </td>
      </tr>
      <tr>
        <td><label for="cluster_size">Cluster Size (Ang): </label></td><td>
            <input style="width: 100px;" type="number" id="cluster_size"
                   name="cluster_size" value="{{ cluster_size }}" step=0.1>
        </td>
        <td  colspan=2>  <input type="checkbox" id="with_h" name="with_h"
                               {% if with_h  %} checked="checked" {% endif %}       >
          <label for="with_h">Include H atoms</label> </td>

      </tr>
      <tr>
        <td colspan=2>
          <input type="submit" name="feff" value="Generate Feff Inputs">
        </td>
        <td colspan=2>
          GENERATE FDMNES Coming Soon
          <!--
          <input type="submit" name="fdmnes" value="Generate FDMNES Input">

          -->
        </td>
      </tr>
    </table>

    <hr>
     CIF Text:<p><pre>{{ciftext|safe}}</pre>

  {% endif %}

     </td>
     <td>
         {% if cif_link or feff_links:  %}
       <div class=subtitle> Download Results </div>
       <table padding=3 >
         <tr><td> File Link</td> <td> Crystal Site/File Type</td></tr>
         {% if cif_link: %}
             <td><a href="{{url_for('ciffile', cifid=cif_link[1], fname=cif_link[0]) }}"> {{
                 cif_link[0] }} </a></td>
             <td> &nbsp;  CIF File </td>
           </tr>
           {% endif %}

         {% if feff_links: %}
         {% for link, data in feff_links.items() %}
           <tr class={{ loop.cycle('even', 'odd') }}>
             <td><a href="{{url_for('feffinp', cifid=data[1],
             absorber=data[2],  edge=data[3], site=data[4],
             cluster_size=data[5], with_h=data[6], fname=link )}}">{{ link }}</a></td>
             <td> &nbsp;  {{ data[0] }} </td>
           </tr>
           {% endfor %}
           {% endif %}
       </table>
           {% endif %}
     </td>
   </tr>
 </table>

</div>

{% endblock %}
