{#  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.html' %}
{% block title %}{{ 'Edit' if adjustment else 'New' }} CGT adjustment{% endblock %}

{% block content %}
	<div class="max-w-lg mx-auto px-4">
		<h1 class="page-heading mb-4">
			{{ 'Edit' if adjustment else 'New' }} CGT adjustment
		</h1>
		
		<form method="POST">
			<div class="grid grid-cols-[max-content_1fr] space-y-2 mb-4 items-baseline">
				<h2 class="col-span-2 text-xl text-gray-900 font-semibold">CGT asset</h2>
				
				<label for="acquisition_date" class="block text-gray-900 pr-4">Acquisition date</label>
				<div>
					<input type="date" class="bordered-field" name="acquisition_date" id="acquisition_date" value="{{ adjustment.acquisition_date.strftime('%Y-%m-%d') if adjustment else request.args.get('acquisition_date', '') }}">
				</div>
				<label for="account" class="block text-gray-900 pr-4">Account</label>
				<div class="relative combobox">
					<input type="text" class="bordered-field peer" name="account" id="account" value="{{ adjustment.account if adjustment else request.args.get('account', '') }}" autocomplete="off">
					{% include 'components/accounts_combobox_inner.html' %}
				</div>
				<label for="asset" class="block text-gray-900 pr-4">Asset</label>
				<div>
					<input type="text" class="bordered-field" name="asset" id="asset" value="{{ adjustment.asset().quantity_string() if adjustment else request.args.get('asset', '') }}">
				</div>
				
				<h2 class="col-span-2 text-xl text-gray-900 font-semibold pt-4">CGT adjustment</h2>
				
				<label for="dt" class="block text-gray-900 pr-4">Adjustment date</label>
				<div>
					<input type="date" class="bordered-field" name="dt" id="dt" value="{{ adjustment.dt.strftime('%Y-%m-%d') if adjustment else '' }}">
				</div>
				<label for="description" class="block text-gray-900 pr-4">Description</label>
				<div>
					<input type="text" class="bordered-field" name="description" id="description" value="{{ adjustment.description if adjustment else '' }}">
				</div>
				<label for="cost_adjustment" class="block text-gray-900 pr-4">Cost adjustment</label>
				<div class="relative shadow-sm">
					<div class="pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3">
						<span class="text-gray-500">$</span>
					</div>
					<input type="number" class="bordered-field pl-7" name="cost_adjustment" id="cost_adjustment" step="0.01" value="{{ adjustment.cost_adjustment_amount().quantity_string() if adjustment else '' }}" placeholder="0.00">
				</div>
			</div>
			
			<div class="text-end">
				<button type="submit" class="btn-primary">Save</button>
			</div>
		</form>
	</div>
{% endblock %}

{% block scripts %}
	<script src="{{ url_for('static', filename='js/combobox.js') }}"></script>
{% endblock %}