{% extends "base.html" %}
{% import "partials/nav.html" as nav %}
{% import "partials/icons.html" as icons %}
{% block title %}{{ mod_info.name }} — Quartermaster{% endblock %}
{% block nav %}{% call nav::nav("mods", user, csrf_token, fika_installed) %}{% endcall %}{% endblock %}
{% block content %}
<h1>{{ mod_info.name }}</h1>

<div class="card">
    <table>
        <tr><th style="width:140px">Forge ID</th><td>{{ mod_info.forge_mod_id }}</td></tr>
        <tr><th>Version</th><td>{{ mod_info.version }}</td></tr>
        {% if let Some(slug) = &mod_info.slug %}
        <tr><th>Slug</th><td>{{ slug }}</td></tr>
        {% endif %}
        <tr><th>Installed</th><td>{{ mod_info.installed_at }}</td></tr>
        {% if let Some(updated) = &mod_info.updated_at %}
        <tr><th>Updated</th><td>{{ updated }}</td></tr>
        {% endif %}
        {% if let Some(slug) = &mod_info.slug %}
        <tr><th>Forge</th><td><a href="https://forge.sp-tarkov.com/mod/{{ mod_info.forge_mod_id }}/{{ slug }}" target="_blank" rel="noopener">View on Forge ↗</a></td></tr>
        {% endif %}
    </table>
</div>

{% if user.role.can_manage_mods() %}
<div class="flex gap-1 mb-2">
    <form method="post" action="/mods/{{ mod_info.id }}/update">
        <input type="hidden" name="csrf_token" value="{{ csrf_token }}">
        <button type="submit" class="btn">{% call icons::refresh() %}{% endcall %} Update</button>
    </form>
    <form method="post" action="/mods/{{ mod_info.id }}/remove"
          data-name="{{ mod_info.name }}"
          onsubmit="return confirm('Remove ' + this.dataset.name + '?')">
        <input type="hidden" name="csrf_token" value="{{ csrf_token }}">
        <button type="submit" class="btn btn-danger">{% call icons::trash() %}{% endcall %} Remove</button>
    </form>
</div>
{% endif %}

{% if !dependencies.is_empty() %}
<div class="card">
    <h2>Dependencies</h2>
    <table>
        <thead><tr><th>Mod</th><th>Constraint</th></tr></thead>
        <tbody>
            {% for dep in &dependencies %}
            <tr>
                <td>
                    {% if let Some(dep_mod) = &dep.dep_mod %}
                    <a href="/mods/{{ dep_mod.id }}">{{ dep_mod.name }}</a>
                    {% else %}
                    <span class="text-muted">Unknown (ID: {{ dep.dep.depends_on_mod_id }})</span>
                    {% endif %}
                </td>
                <td class="text-muted">{{ dep.dep.version_constraint.as_deref().unwrap_or("any") }}</td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
</div>
{% endif %}

<div class="card">
    <h2>Installed Files ({{ archive_files.len() }})</h2>
    <table>
        <thead><tr><th>Path</th><th>Size</th></tr></thead>
        <tbody>
            {% for f in &archive_files %}
            <tr>
                <td class="text-sm">{{ f.file_path }}</td>
                <td class="text-muted text-sm">{{ f.file_size|format_size }}</td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
</div>

{% if !runtime_files.is_empty() %}
<div class="card" style="border-left: 3px solid var(--warning)">
    <h2>Runtime Files ({{ runtime_files.len() }})</h2>
    <p class="text-muted text-sm">Generated by the mod after installation — configs, caches, databases.</p>
    <table>
        <thead><tr><th>Path</th><th>Size</th></tr></thead>
        <tbody>
            {% for f in &runtime_files %}
            <tr>
                <td class="text-sm">{{ f.file_path }}</td>
                <td class="text-muted text-sm">{{ f.file_size|format_size }}</td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
</div>
{% endif %}
{% endblock %}
