<tal:block define="global isBdrDeployment python: here.ReportekEngine.getDeploymentType() == 'BDR'"/>
<metal:block use-macro="container/standard_template.pt/macros/page">
  <metal:block fill-slot="head">
    <link href="++resource++static/select2-3.5.0/select2.css" rel="stylesheet"/>
    <link href="++resource++static/style.css" rel="stylesheet"/>
    <link href="++resource++static/envelope.css" rel="stylesheet"/>
    <link href="++resource++static/fontawesome/font-awesome.min.css" rel="stylesheet"/>
    <script type="text/javascript" charset="utf8" src="++resource++static/jquery-3.5.1.min.js"></script>
    <script src="++resource++static/active_status.js"></script>
  </metal:block>
  <metal:block fill-slot="content">
    <tal:block condition="python:context.canViewContent()">
      <div tal:replace="structure python:context.envelope_tabs(tab='overview')"/>

      <div id="operations">
        <ul>
          <tal:block condition="python:context.canAddFeedback()">
            <li><a href="manage_addFeedbackForm" title="Post feedback for this release"
                   i18n:attributes="title"
                   i18n:translate="">Add feedback</a></li>
          </tal:block>
            <li><a href="envelope_zip" rel="nofollow" title="Download zipped envelope with available files"
                   i18n:attributes="title"
                   i18n:translate="">Zip envelope</a></li>
          <div tal:replace="structure python:context.activity_operations(REQUEST=context.REQUEST)"/>
        </ul>
      </div>

      <h1 tal:content="python:context.title_or_id()"></h1>

      <div class="metadata" 
        tal:define="df_prefix python: 'http://rod.eionet.europa.eu/obligations/{}';
                    is_ods python: df_prefix.format('213') in here.dataflow_uris;
                    is_fgas python: df_prefix.format('713') in here.dataflow_uris;
                    is_fgas_verification python: df_prefix.format('764') in here.dataflow_uris or df_prefix.format('765') in here.dataflow_uris;">
        <table border="0" cellspacing="2" cellpadding="2">
          <tbody>
            <tr tal:attributes="class python: 'hidden-content' if is_fgas or is_ods or is_fgas_verification else ''">
              <th i18n:translate="">Description</th>
              <td tal:content="python:context.descr"></td>
            </tr>
            <tr>
              <th i18n:translate="">Obligations</th>
              <td tal:define="engine context/getEngine">
                <tal:block condition="python:context.dataflow_uris" repeat="uri python:context.dataflow_uris">
                  <tal:block define="df python:engine.dataflow_lookup(uri)">
                    <a tal:attributes="href python:df['details_url']"
                       tal:content="python:df['TITLE']"></a>
                    <tal:block condition="python:df.get('terminated', '0') == '1'">
                     <em i18n:translate="">Terminated</em>
                    </tal:block>
                    <br/>
                  </tal:block>
                </tal:block>

                <tal:block condition="python:not context.dataflow_uris">
                  <span style="color:maroon;font-weight:bold"
                        title="The obligation tag makes it possible for the requesters to find the delivery"
                        i18n:attributes="title"
                        i18n:translate="">
                    Notice: this envelope has no obligation tag</span>
                </tal:block>
              </td>
            </tr>
            <tr>
              <th>
                <span tal:condition="python: not (is_fgas or is_ods or is_fgas_verification)" i18n:translate="">Period</span>
                <span tal:condition="python: is_fgas or is_ods or is_fgas_verification" i18n:translate="">Transaction year</span>
              </th>
              <tal:block tal:condition="python: not (is_fgas or is_ods or is_fgas_verification)">
                <td tal:condition="python:context.endyear == ''"
                    tal:content="python:'%s - %s' %(context.year, context.friendlypartofyear)">
                </td>
                <td tal:condition="not:python:context.endyear == ''"
                    tal:content="python:'%s to %s' %(context.year, context.endyear)">
                </td>
              </tal:block>
              <tal:block tal:condition="python: is_fgas or is_ods or is_fgas_verification">
                <td>
                  <span tal:content="context/get_transaction_year"/>
                </td>
              </tal:block>
            </tr>
            <tr>
              <th i18n:translate="">Coverage</th>
              <td tal:content="context/getCountryName">
                <span tal:condition="context/locality" tal:replace="python:': %s' %context.locality"></span>
              </td>
            </tr>
            <tal:block condition="context/released">
              <tr>
                <th i18n:translate="">Reported</th>
                <td tal:content="python: context.reportingdate.strftime('%d %b %Y %H:%M')" />
              </tr>
            </tal:block>
            <tr tal:condition="isBdrDeployment">
              <th i18n:translate="">Acceptability status</th>
              <td tal:define="statuses
                                 python:{
                                      True: 'Data delivery is acceptable',
                                      False: 'Data delivery is not acceptable',};
                              ok_acceptable python: context.is_acceptable() and context.successful_qa;
                              unknown python: context.has_unknown_qa_result and ok_acceptable;"
                  tal:content="python: 'N/A' if unknown else statuses.get(context.is_acceptable() and context.successful_qa, 'N/A')">
              </td>
          </tr>
            <tr>
              <td colspan="2">
                <tal:block condition="not:python:context.status in ('running', 'active')">
                  <div class="dynamic-status env-completed">
                    <div class="ds-wrapper">
                      <div class="ds-head">
                        <span i18n:translate="" class="title">Status: </span>
                        <span i18n:translate="">
                          Envelope is <span i18n:name="status" tal:replace="context/status"></span> 
                          <tal:def tal:define="fb_ta python: context.get('feedbackTA');
                                              fb_cor python: context.get('feedbackCoR');
                                              ff_fb python: fb_ta or fb_cor">
                            <span tal:condition="python: ff_fb"> (<span tal:content="ff_fb/title_or_id|nothing"/>)</span>
                          </tal:def>
                        </span>
                      </div>
                    </div>
                  </div>
                </tal:block>
                <tal:block define="activeW python:context.getListOfWorkitems('active');
                                   inactiveW python:context.getListOfWorkitems('inactive');
                                   of_interest python: [context.getListOfWorkitems(status=['active', 'complete'])[-1]] if not inactiveW and not context.status == 'complete' else [];
                                   w_items python:[wi for wi in context.getListOfWorkitems()];
                                   last python: w_items[-1].activity_id if w_items else None;
                                   ">
                  <metal:block use-macro="here/macros/tasks_in_progress">
                  </metal:block>
                </tal:block>
              </td>
            </tr>
          </tbody>
        </table>
      </div>

      <div class="note-msg" tal:condition="context/uns_notifications_are_on">
        <strong i18n:translate="">Note</strong>
        <p i18n:translate="">
          If you want to stay updated about events in this envelope
          <span i18n:name="subscribe">
            <a href="ReportekEngine/subscriptions_html" i18n:translate="">
              Subscribe to receive notifications
            </a>
          </span> for this country and the current dataflow(s).
        </p>
      </div>

      <form id="objectItems" method="post"
            tal:define="action_url python:context.absolute_url()"
            tal:attributes="action string:${action_url}/">

      <div tal:replace="structure context/documents_section"/>

      <tal:block condition="not:context/released">
      <strong i18n:translate="">Remember to release the envelope when you have uploaded all files</strong>
      </tal:block>

      <div tal:replace="structure context/feedback_section"/>

      </form>
    </tal:block>
    <tal:block condition="not:python:context.canViewContent()">
      <h1 i18n:translate="">Not available</h1>
      <p i18n:translate="">This envelope is not yet available for public view.
      Work is still in progress.</p>
    </tal:block>
  </metal:block>
</metal:block>
