{#  DrCr: Web-based double-entry bookkeeping framework
    Copyright (C) 2022–2023  Lee Yingtong Li (RunasSudo)

    This program 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.

    This program 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 this program.  If not, see <https://www.gnu.org/licenses/>.
#}

{% extends 'base.html' %}
{% block title %}Chart of accounts{% endblock %}

{% block content %}
	<h1 class="h2 mt-4 mb-2">Chart of accounts</h1>
	
	<form method="POST">
		<div class="d-flex py-2 bg-white sticky-top">
			<div class="me-2">
				<select class="form-select" name="kind">
					{% for plugin_name, plugin_account_kinds in account_kinds_by_plugin.items() %}
						<optgroup label="{{ plugin_name }}">
							{% for account_kind in plugin_account_kinds %}
								<option value="{{ account_kind[0] }}">{{ account_kind[1] }}</option>
							{% endfor %}
						</optgroup>
					{% endfor %}
				</select>
			</div>
			<div>
				<button type="submit" class="btn btn-primary" formaction="{{ url_for('account_add_kind') }}">Add kind</button>
			</div>
		</div>
		
		<table class="table">
			<thead>
				<tr>
					<th></th>
					<th>Account</th>
					<th>Associated types</th>
				</tr>
			</thead>
			<tbody>
				{% for account in accounts %}
					<tr>
						<td><input type="checkbox" name="sel-account" value="{{ account }}"></td>
						<td>{{ account }}</td>
						<td>
							{% if account in account_configurations %}
								<ul class="mb-0">
									{% for account_configuration in account_configurations[account] %}
										<li>{{ account_kinds_map[account_configuration.kind] }}</li>
									{% endfor %}
								</ul>
							{% endif %}
						</td>
					</tr>
				{% endfor %}
			</tbody>
		</table>
	</form>
{% endblock %}