{% extends "ui/templates/base/layout.html" %}
{% block content %}
  <h1 class="text-2xl font-semibold">Create Financial Year</h1>
  <form class="mt-5 max-w-2xl rounded-2xl border bg-white p-5" method="post">
    <input type="hidden" name="csrf_token" value="{{ csrf_token }}" />
    <div class="grid gap-4">
      {% if tenants|length > 1 %}
      <label class="grid gap-1">
        <span class="text-sm font-medium text-slate-600">Audit Firm</span>
        <select name="tenant_id" class="rounded-xl border px-3 py-2" required>
          {% for tenant in tenants %}
          <option value="{{ tenant.id }}" {% if tenant.id == selected_tenant_id %}selected{% endif %}>{{ tenant.name }} ({{ tenant.code }})</option>
          {% endfor %}
        </select>
      </label>
      {% else %}
      <input type="hidden" name="tenant_id" value="{{ selected_tenant_id }}" />
      {% endif %}

      <div class="grid grid-cols-1 gap-4 md:grid-cols-2">
        <label class="grid gap-1">
          <span class="text-sm font-medium text-slate-600">Financial Year Code</span>
          <input class="rounded-xl border px-3 py-2" name="year_code" value="{{ form_data.year_code or '' }}" placeholder="2025-26" required />
        </label>
        <label class="grid gap-1">
          <span class="text-sm font-medium text-slate-600">Assessment Year</span>
          <input class="rounded-xl border px-3 py-2" name="assessment_year" value="{{ form_data.assessment_year or '' }}" placeholder="2026-27" required />
        </label>
        <label class="grid gap-1">
          <span class="text-sm font-medium text-slate-600">Start Date</span>
          <input type="date" class="rounded-xl border px-3 py-2" name="start_date" value="{{ form_data.start_date or '' }}" required />
        </label>
        <label class="grid gap-1">
          <span class="text-sm font-medium text-slate-600">End Date</span>
          <input type="date" class="rounded-xl border px-3 py-2" name="end_date" value="{{ form_data.end_date or '' }}" required />
        </label>
      </div>

      <label class="flex items-center gap-2 rounded-xl border bg-slate-50 px-3 py-2">
        <input type="checkbox" name="is_current" />
        <span class="text-sm text-slate-700">Make this the current financial year for this audit firm</span>
      </label>

      <div class="flex gap-3">
        <button class="rounded-xl bg-slate-900 px-4 py-2 text-sm font-medium text-white" type="submit">Save</button>
        <a class="rounded-xl border px-4 py-2 text-sm" href="/system-settings/financial-years?tenant_id={{ selected_tenant_id }}">Cancel</a>
      </div>
    </div>
  </form>
{% endblock %}
