{* Anfrage-Protokoll tab — MCP request log viewer. All dynamic values escaped.
   Tailwind only, via `$ui` (adminmenu/Controller/Ui.php). *}
<div class="tnt-mcp-request-log py-4">
    <div class="{$ui.card}">
        <div class="{$ui.cardHead}">
            <span>
                {if $lang == 'en'}
                    MCP requests (newest first, max. {$limit|intval})
                {else}
                    MCP-Anfragen (neueste zuerst, max. {$limit|intval})
                {/if}
            </span>
        </div>
        <div class="{$ui.cardBody}">
            {if $entries}
                <div class="{$ui.tableWrap} {$ui.tableScroll}">
                    <table class="{$ui.table}">
                        <thead>
                        <tr>
                            <th class="{$ui.thSticky}">{if $lang == 'en'}Time{else}Zeit{/if}</th>
                            <th class="{$ui.thSticky}">{if $lang == 'en'}Tool / endpoint{else}Tool / Endpunkt{/if}</th>
                            <th class="{$ui.thSticky}">{if $lang == 'en'}Parameters{else}Parameter{/if}</th>
                            <th class="{$ui.thSticky}">Auth</th>
                            <th class="{$ui.thSticky} text-right">Status</th>
                            <th class="{$ui.thSticky} text-right">{if $lang == 'en'}Duration (ms){else}Dauer (ms){/if}</th>
                        </tr>
                        </thead>
                        <tbody>
                        {foreach $entries as $e}
                            <tr>
                                <td class="{$ui.td} whitespace-nowrap">{$e.time|escape}</td>
                                <td class="{$ui.td}">
                                    {* The tool name is the answer to "what happened?" — the
                                       endpoint is `tools/call` on nearly every row (ledger U25). *}
                                    {if $e.tool}
                                        <code class="{$ui.code}">{$e.tool|escape}</code>
                                        <div class="{$ui.small}">{$e.endpoint|escape}</div>
                                    {else}
                                        <code class="{$ui.code}">{$e.endpoint|escape}</code>
                                    {/if}
                                </td>
                                <td class="{$ui.td} {$ui.small}">{$e.args|escape}</td>
                                <td class="{$ui.td}">
                                    {assign var=auth value=$e.auth}
                                    {* `legacy` used to be painted the same green as `oauth`, which hid
                                       exactly the connections this plugin wants migrated (ledger U15). *}
                                    {if $auth === 'oauth'}
                                        <span class="{$ui.chip.success}">{$auth|escape}</span>
                                    {elseif $auth === 'legacy'}
                                        <span class="{$ui.chip.warning}"
                                              title="{if $lang == 'en'}Static token — migrate this connection to OAuth{else}Statischer Token – diese Verbindung auf OAuth umstellen{/if}">{$auth|escape}</span>
                                    {elseif $auth === 'invalid'}
                                        <span class="{$ui.chip.danger}">{$auth|escape}</span>
                                    {else}
                                        <span class="{$ui.chip.neutral}">{$auth|escape}</span>
                                    {/if}
                                </td>
                                <td class="{$ui.td} text-right">
                                    {assign var=st value=$e.status|intval}
                                    {* An `auth_challenge` 401 IS the OAuth handshake, not a failure
                                       — red there trains the merchant to ignore red (ledger U27). *}
                                    {if $e.handshake}
                                        <span class="{$ui.chip.neutral}"
                                              title="{if $lang == 'en'}Normal sign-in handshake, not an error{else}Normaler Anmelde-Handshake, kein Fehler{/if}">{$st}</span>
                                    {elseif $st >= 200 && $st < 300}
                                        <span class="{$ui.chip.success}">{$st}</span>
                                    {elseif $st >= 400}
                                        <span class="{$ui.chip.danger}">{$st}</span>
                                    {else}
                                        <span class="{$ui.chip.neutral}">{$st}</span>
                                    {/if}
                                </td>
                                <td class="{$ui.td} text-right">{$e.duration|intval}</td>
                            </tr>
                        {/foreach}
                        </tbody>
                    </table>
                </div>
            {else}
                <span class="{$ui.muted}">
                    {if $lang == 'en'}No requests logged yet.{else}Noch keine Anfragen protokolliert.{/if}
                </span>
            {/if}
        </div>
    </div>
</div>
