{#  DrCr: Web-based double-entry bookkeeping framework
    Copyright (C) 2022–2024  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_tailwind.html' %}
{% block title %}Chart of accounts{% endblock %}

{% block content %}
	<h1 class="text-3xl text-gray-900">
		Chart of accounts
	</h1>
	
	<form method="POST">
		<div class="my-2 py-2 flex gap-x-2 items-baseline bg-white sticky top-0">
			<div>
				<select class="mt-2 block w-full border-0 py-1 pl-3 pr-10 text-gray-900 ring-1 ring-inset ring-gray-300 focus:ring-2 focus:ring-indigo-600" 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 formaction="{{ url_for('account_add_kind') }}" class="bg-emerald-600 px-3 py-1 text-white shadow-sm hover:bg-emerald-700" type="submit">Add type</button>
			</div>
		</div>
		
		<table class="min-w-full">
			<thead>
				<tr>
					<th></th>
					<th class="py-0.5 text-gray-900 font-semibold text-start">Account</th>
					<th class="py-0.5 text-gray-900 font-semibold text-start">Associated types</th>
				</tr>
			</thead>
			<tbody>
				{% for account in accounts %}
					<tr class="border-t border-gray-300">
						<td class="py-0.5 text-gray-900 align-baseline"><input class="h-4 w-4 border-gray-300 text-emerald-600 focus:ring-emerald-600 -mt-0.5" type="checkbox" name="sel-account" value="{{ account }}"></td>
						<td class="py-0.5 text-gray-900 align-baseline">{{ account }}</td>
						<td class="py-0.5 text-gray-900 align-baseline">
							{% if account in account_configurations %}
								<ul class="list-disc ml-5">
									{% 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 %}