{% extends "ui/templates/base/layout.html" %}
{% block content %}
  {% set ui_perms = current_user_permissions or [] %}
  {% set ui_roles = current_user_roles or [] %}

  <h1 class="text-2xl font-semibold">Workspace</h1>
  <p class="text-slate-600 mt-1">
    Welcome{% if current_user and current_user.full_name %}, {{ current_user.full_name }}{% endif %}.
    Use the options available for your access level.
  </p>

  {% set show_admin_cards =
      can_view_tenants(current_user, ui_perms, ui_roles)
      or can_view_branches(current_user, ui_perms, ui_roles)
      or can_view_users(current_user, ui_perms, ui_roles)
      or can_view_audit(current_user, ui_perms, ui_roles)
      or can_view_rbac(current_user, ui_perms, ui_roles)
      or ("Firm Admin" in ui_roles)
  %}

  {% if show_admin_cards %}
    <div class="mt-6 grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-3">

      {% if can_view_tenants(current_user, ui_perms, ui_roles) %}
      <a href="/system-settings/tenants" class="rounded-2xl bg-white border p-5 hover:shadow-sm">
        <div class="font-semibold">Audit Firms</div>
        <div class="text-sm text-slate-600 mt-1">Create and manage audit firms.</div>
      </a>
      {% endif %}

      {% if can_view_branches(current_user, ui_perms, ui_roles) %}
      <a href="/system-settings/branches" class="rounded-2xl bg-white border p-5 hover:shadow-sm">
        <div class="font-semibold">Branches</div>
        <div class="text-sm text-slate-600 mt-1">Branch settings, SMTP, storage, identity and policy controls.</div>
      </a>
      {% endif %}

      {% if can_view_settings(current_user, ui_perms, ui_roles) %}
      <a href="/system-settings/financial-years" class="rounded-2xl bg-white border p-5 hover:shadow-sm">
        <div class="font-semibold">Financial Years</div>
        <div class="text-sm text-slate-600 mt-1">Create, switch, lock, backup and manage financial year context.</div>
      </a>
      {% endif %}

      {% if "Firm Admin" in ui_roles or "System Admin" in ui_roles %}
      <a href="/system-settings/branding" class="rounded-2xl bg-white border p-5 hover:shadow-sm">
        <div class="font-semibold">Firm Branding</div>
        <div class="text-sm text-slate-600 mt-1">Logo, favicon, standard colours, contact details and invoice defaults.</div>
      </a>
      {% endif %}

      {% if "Firm Admin" in ui_roles or "System Admin" in ui_roles %}
      <a href="/email/settings" class="rounded-2xl bg-white border p-5 hover:shadow-sm">
        <div class="font-semibold">Firm Email / SMTP</div>
        <div class="text-sm text-slate-600 mt-1">Configure SMTP, IMAP, sender identity and authentication email delivery.</div>
      </a>
      <a href="/email/templates" class="rounded-2xl bg-white border p-5 hover:shadow-sm">
        <div class="font-semibold">Email Templates</div>
        <div class="text-sm text-slate-600 mt-1">Edit OTP, password reset, invite and notification email templates.</div>
      </a>
      {% endif %}

      {% if can_view_users(current_user, ui_perms, ui_roles) %}
      <a href="/system-settings/users" class="rounded-2xl bg-white border p-5 hover:shadow-sm">
        <div class="font-semibold">Users</div>
        <div class="text-sm text-slate-600 mt-1">Manage user accounts, access and lifecycle actions.</div>
      </a>
      {% endif %}

      {% if can_view_rbac(current_user, ui_perms, ui_roles) %}
      <a href="/system-settings/rbac/roles" class="rounded-2xl bg-white border p-5 hover:shadow-sm">
        <div class="font-semibold">RBAC</div>
        <div class="text-sm text-slate-600 mt-1">Configure roles and permissions.</div>
      </a>
      {% endif %}

      {% if can_view_audit(current_user, ui_perms, ui_roles) %}
      <a href="/system-settings/audit-logs" class="rounded-2xl bg-white border p-5 hover:shadow-sm">
        <div class="font-semibold">Audit Logs</div>
        <div class="text-sm text-slate-600 mt-1">Review recorded actions for your allowed scope.</div>
      </a>
      {% endif %}
    </div>
  {% else %}
    <div class="mt-6 rounded-2xl border bg-white p-6 shadow-soft">
      <div class="text-lg font-semibold text-slate-900">Your workspace is ready</div>
      <p class="mt-2 text-sm text-slate-600">
        Admin modules are not assigned to your current role. Profile, task, and other user-facing features can be added here next.
      </p>

      <div class="mt-4 grid gap-3 md:grid-cols-2">
        <div class="rounded-xl border border-slate-200 bg-slate-50 p-4">
          <div class="font-medium text-slate-800">Profile / Account</div>
          <div class="mt-1 text-sm text-slate-600">
            Use this area later for profile, password change, notifications, and personal settings.
          </div>
        </div>

        <div class="rounded-xl border border-slate-200 bg-slate-50 p-4">
          <div class="font-medium text-slate-800">Upcoming Features</div>
          <div class="mt-1 text-sm text-slate-600">
            Staff dashboard, tasks, attendance, documents, and other user workspace modules can be plugged in here.
          </div>
        </div>
      </div>
    </div>
  {% endif %}
{% endblock %}