{% extends "ui/templates/base/layout.html" %}
{% block content %}
  <h1 class="text-2xl font-semibold">Edit Audit Firm</h1>

  <form class="mt-4 rounded-2xl bg-white border p-5 max-w-3xl" method="post">
    <input type="hidden" name="csrf_token" value="{{ csrf_token }}" />

    <div class="grid gap-5">
      <div class="grid grid-cols-1 md:grid-cols-2 gap-3">
        <label class="grid gap-1">
          <span class="text-sm text-slate-600">Audit Firm Code</span>
          <input class="border rounded-xl px-3 py-2 bg-slate-50" name="code" value="{{ tenant.code }}" readonly />
        </label>

        <label class="grid gap-1">
          <span class="text-sm text-slate-600">Audit Firm Name</span>
          <input class="border rounded-xl px-3 py-2" name="name" value="{{ tenant.name }}" required />
        </label>

        <label class="grid gap-1 md:col-span-2">
          <span class="text-sm text-slate-600">Audit Firm Type</span>
          <select class="border rounded-xl px-3 py-2" name="firm_type" required>
            <option value="partnership" {% if (tenant.firm_type or 'proprietorship') == 'partnership' %}selected{% endif %}>Partnership Firm</option>
            <option value="proprietorship" {% if tenant.firm_type == 'proprietorship' %}selected{% endif %}>Proprietorship Firm</option>
            <option value="individual" {% if tenant.firm_type == 'individual' %}selected{% endif %}>Individual Audit Practice</option>
          </select>
          <span class="text-xs text-slate-500">Review partner is applicable only for partnership firms and assurance engagements.</span>
        </label>
      </div>

      <div class="border-t pt-4">
        <div class="font-semibold">Audit Firm Default Policies</div>
        <div class="grid grid-cols-1 md:grid-cols-2 gap-3 mt-3">
          <label class="grid gap-1">
            <span class="text-sm text-slate-600">Default Timezone</span>
            <input class="border rounded-xl px-3 py-2" name="default_timezone" value="{{ tenant.default_timezone or 'Asia/Kolkata' }}" />
          </label>

          <label class="grid gap-1">
            <span class="text-sm text-slate-600">Default Session Duration (minutes)</span>
            <input class="border rounded-xl px-3 py-2" name="default_session_duration_minutes" value="{{ tenant.default_session_duration_minutes or 480 }}" />
          </label>

          <label class="grid gap-1 md:col-span-2">
            <span class="text-sm text-slate-600">Default OTP Required Roles (CSV)</span>
            <input class="border rounded-xl px-3 py-2" name="default_otp_required_roles_csv" value="{{ tenant.default_otp_required_roles_csv or 'System Admin' }}" />
          </label>

          <label class="grid gap-1">
            <span class="text-sm text-slate-600">Default Storage Mode</span>
            <select class="border rounded-xl px-3 py-2" name="default_storage_mode">
              {% for value in ['local_only','cloud_only','hybrid'] %}
              <option value="{{ value }}" {% if (tenant.default_storage_mode or 'local_only') == value %}selected{% endif %}>{{ value }}</option>
              {% endfor %}
            </select>
          </label>

          <label class="flex items-center gap-2 text-sm text-slate-700">
            <input type="checkbox" name="is_active" value="1" {% if tenant.is_active %}checked{% endif %} /> Active
          </label>
        </div>
      </div>

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

