{% extends "ui/templates/base/layout.html" %}{% block content %}
<div class="space-y-6"><div class="flex items-center justify-between"><div><h1 class="text-2xl font-semibold">Client Portal Identity</h1><p class="text-sm text-slate-500">{{ client.client_name }} · PAN {{ client.pan or 'Not available' }}</p></div><a href="/clients/{{ client.id }}" class="rounded-xl border px-4 py-2 text-sm">Back to Client</a></div>
{% if flash %}<div class="rounded-xl border border-sky-200 bg-sky-50 p-4 text-sm text-sky-900">{{ flash }}</div>{% endif %}
{% if invite_url %}<div class="rounded-xl border border-amber-300 bg-amber-50 p-4"><div class="font-semibold">Invitation link — copy now</div><input class="mt-2 w-full rounded-lg border px-3 py-2 font-mono text-xs" readonly value="{{ invite_url }}"><p class="mt-2 text-xs text-amber-800">This plain token is displayed only once.</p></div>{% endif %}
{% if not identity %}<section class="rounded-2xl bg-white p-6 shadow-soft"><h2 class="font-semibold">Create PAN-linked identity</h2><p class="mt-1 text-sm text-slate-500">PAN is the permanent identity. Email may be added or changed later.</p><form method="post" action="/client-identity/clients/{{ client.id }}/create" class="mt-4 grid gap-3 max-w-xl"><input type="hidden" name="csrf_token" value="{{ csrf_token }}"><label class="text-sm">Initial login email (optional)<input name="email" type="email" value="{{ client.email or '' }}" class="mt-1 w-full rounded-xl border px-3 py-2"></label><button class="rounded-xl bg-slate-900 px-4 py-2 text-white">Create identity</button></form></section>{% else %}
<div class="grid gap-6 lg:grid-cols-2"><section class="rounded-2xl bg-white p-6 shadow-soft"><h2 class="font-semibold">Identity</h2><dl class="mt-4 grid gap-3 text-sm"><div><dt class="text-slate-500">PAN login</dt><dd class="font-mono">{{ identity.normalized_pan }}</dd></div><div><dt class="text-slate-500">Email login</dt><dd>{{ identity.login_email }}</dd></div><div><dt class="text-slate-500">Status</dt><dd>{{ identity.status|replace('_',' ')|title }}</dd></div></dl>{% if can_manage %}<form method="post" action="/client-identity/clients/{{ client.id }}/email" class="mt-5 grid gap-3"><input type="hidden" name="csrf_token" value="{{ csrf_token }}"><label class="text-sm">Change email<input name="email" required type="email" value="{{ '' if identity.email_is_placeholder else identity.login_email }}" class="mt-1 w-full rounded-xl border px-3 py-2"></label><button class="rounded-xl border px-4 py-2">Update email</button></form>{% endif %}</section>
<section class="rounded-2xl bg-white p-6 shadow-soft"><h2 class="font-semibold">Invitation</h2><p class="mt-1 text-sm text-slate-500">Issue or reissue a single-use password setup link.</p>{% if can_manage %}<form method="post" action="/client-identity/clients/{{ client.id }}/invite" class="mt-4 grid gap-3"><input type="hidden" name="csrf_token" value="{{ csrf_token }}"><label class="text-sm"><select name="send_email" class="w-full rounded-xl border px-3 py-2"><option value="1">Email and show link</option><option value="0">Show link only</option></select></label><button class="rounded-xl bg-brand-600 px-4 py-2 text-white">Issue invitation</button></form>{% endif %}</section></div>
<section class="rounded-2xl bg-white p-6 shadow-soft"><h2 class="font-semibold">Invitation history</h2><div class="mt-3 overflow-x-auto"><table class="w-full text-sm"><thead><tr class="text-left text-slate-500"><th class="py-2">Issued</th><th>Mode</th><th>Recipient</th><th>Status</th><th>Expiry</th></tr></thead><tbody>{% for x in invites %}<tr class="border-t"><td class="py-2">{{ x.issued_at_utc }}</td><td>{{ x.delivery_mode }}</td><td>{{ x.recipient_email or '-' }}</td><td>{{ x.status }}</td><td>{{ x.expires_at_utc or '-' }}</td></tr>{% else %}<tr><td colspan="5" class="py-4 text-slate-500">No invitations issued.</td></tr>{% endfor %}</tbody></table></div></section>{% endif %}</div>
{% endblock %}
