{#
    This file is part of Accountant.

    Accountant is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Foobar is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with Accountant.  If not, see <http://www.gnu.org/licenses/>.
#}
{% extends "layout.html" %}
{% block body %}
<div ng-controller="EntryController">
<!-- Chart row -->
<div class="row">
  <!-- Sold evolution chart placeholder -->
  <div class="col-md-7">
      <svg id="entries-chart-placeholder" style="stroke-width: 1px"/>
  </div>

  <!-- Expense category piechart -->
  <div class="col-md-3">
      <svg id="expense-categories-chart-placeholder" style='height:300px'/>
  </div>

  <!-- Balance -->
  <div class="col-md-2">
    <div class="row">
      <table class="table">
        <tr><td>Dépenses&nbsp;:</td><td>[[accountStatus.expenses]]</td></tr>
        <tr><td>Recettes&nbsp;:</td><td>[[accountStatus.revenues]]</td></tr>
        <tr><td>Balance&nbsp;:</td><td><span ng-class="entryValueClass(accountStatus.balance)">[[accountStatus.balance]]</span></td></tr>
      </table>
    </div>
  </div>
</div>

<!-- Row with entry table -->
<div class="row">
  <table class="table table-condensed table-hover">
    <!-- Head of the table containing column headers and size -->
    <thead>
      <tr>
        <th style="width: 100px">Date d'op.</th>
        <th>Libell&eacute; de l'op&eacute;ration</th>
        <th style="width: 50px">Montant</th>
        <th style="width: 50px">Solde</th>
        <th style="width: 100px">Cat&eacute;gorie</th>
        <th style="width: 80px">Actions</th>
      </tr>
    </thead>

    <!-- Body of the table containing the entries -->
    <tbody>
      <tr id="entry_[[entry.id]]" class="form-inline" ng-class="entryRowClass(entry)" ng-repeat="entry in entries">
        <td>
          <small>
            <input ng-show="isEditing(entry)" type="text" class="form-control input-sm" ng-model="entry.operation_date" data-date-format="yyyy-mm-dd" bs-datepicker/>
            <span ng-show="isDisplaying(entry)">[[entry.operation_date]]</span>
          </small>
        </td>
        
        <td>
          <small>
            <input ng-show="isEditing(entry)" type="text" class="form-control input-sm" ng-model="entry.label"/>
            <span ng-show="isDisplaying(entry)">[[entry.label]]</span>
          </small>
        </td>
        
        <td>
          <small>
            <input ng-show="isEditing(entry)" type="text" class="form-control input-sm" ng-model="entry.value"/>
            <span ng-show="isDisplaying(entry)">[[entry.value]]</span>
          </small>
        </td>
        
        <td ng-class="entryValueClass(entry.sold)">
          <small>
              [[entry.sold]]
          </small>
        </td>

        <td>
          <small>
              <!--<input ng-show="isEditing(entry)" type="text" class="form-control input-sm" ng-model="entry.category" bs-typeahead="categories"/>-->
            <input ng-show="isEditing(entry)" type="text" class="form-control input-sm" ng-model="entry.category"/>
            <span ng-show="isDisplaying(entry)">[[entry.category]]</span>
          </small>
        </td>

        <td>
          <div class="btn-group" ng-show="isEditing(entry)">
            <button type="button" class="btn btn-xs btn-success" ng-click="saveEntry(entry)" title="Save">
              <span ng-class="iconSaveClass(entry)"></span>
            </button>

            <button type="button" class="btn btn-xs btn-default" ng-click="cancelEditEntry(entry)" title="Cancel">
              <span ng-class="iconCancelClass(entry)"></span>
            </button>

            <button type="button" class="btn btn-xs btn-default" ng-click="pointEntry(entry)" ng-class="pointedEntryClass(entry)" title="point">
              <span class="fa fa-check"></span>
            </button>
          </div>

          <div class="btn-group" ng-show="isDisplaying(entry) && isSaved(entry)">
            <button class="btn btn-xs btn-default" ng-click="editEntry(entry)" title="edit">
              <span class="fa fa-pencil-square-o"></span>
            </button>

            <button class="btn btn-xs btn-default" ng-click="removeEntry(entry)" title="remove">
              <span class="fa fa-trash-o"></span>
            </button>

            <button class="btn btn-xs btn-default" ng-click="pointEntry(entry)" ng-class="pointedEntryClass(entry)" title="point">
              <span class="fa fa-check"></span>
            </button>
          </div>

          <div class="btn-group" ng-show="isDisplaying(entry) && !isSaved(entry)">
            <button class="btn btn-xs btn-success" ng-click="saveEntry(entry)" title="Save">
              <span ng-class="iconSaveClass(entry)"></span>
            </button>

            <button class="btn btn-xs btn-default" ng-click="editEntry(entry)" title="edit">
              <span class="fa fa-pencil-square-o"></span>
            </button>

            <button class="btn btn-xs btn-default" ng-click="pointEntry(entry)" ng-class="pointedEntryClass(entry)" title="point">
              <span class="fa fa-check"></span>
            </button>
          </div>
        </td>
      </tr>
    </tbody>
  </table>
</div>

{% include "remove_entry.html" %}

</div>
{% endblock %}

{% block footer %}
<!-- Navbar with the months of the selected account -->
<div class="navbar navbar-default  navbar-fixed-bottom" role="navigation" ng-controller="MonthController">
  <ul class="nav navbar-nav">
    <li ng-repeat="month in months" ng-class="monthClass(month)"><a href="#" ng-click="selectMonth(month)">[[month.year]]-[[month.month]]</a></li>
  </ul>
</div>
{% endblock %}


<!-- Custom Javascript library for entries -->
{% block js %}
<script type="text/javascript" src="{{ url_for('frontend.static', filename='js/months.js') }}"></script>
<script type="text/javascript" src="{{ url_for('frontend.static', filename='js/accounts.js') }}"></script>
<script type="text/javascript" src="{{ url_for('frontend.static', filename='js/entries.js') }}"></script>
{% endblock %}