{{ extends "../layouts/base" }}

{{ block title() }}Process Manager - HeroApp UI{{ end }}

{{ block body() }}
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
    <h1 class="h2">Process Manager</h1>
    <div class="btn-toolbar mb-2 mb-md-0">
        <button type="button" class="btn btn-sm btn-outline-secondary" onclick="location.reload()">
            <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-refresh-cw"><polyline points="23 4 23 10 17 10"></polyline><polyline points="1 20 1 14 7 14"></polyline><path d="M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15"></path></svg>
            Refresh
        </button>
    </div>
</div>

<div class="table-responsive">
    <table class="table table-striped table-sm table-hover">
        <thead>
            <tr>
                <th scope="col">PID</th>
                <th scope="col">Name</th>
                <th scope="col">CPU (%)</th>
                <th scope="col">Memory (MB)</th>
                <th scope="col">Actions</th>
            </tr>
        </thead>
        <tbody>
            {{ if len(Processes) > 0 }}
                {{ range pid, process := Processes }}
                <tr>
                    <td>{{ pid }}</td>
                    <td>{{ process.Name }}</td>
                    <td>{{ process.CPU  }}</td>
                    <td>{{ process.Memory }}</td>
                    <td>
                        <form action="/processes/kill/{{ pid }}" method="POST" style="display:inline;">
                            <button type="submit" class="btn btn-danger btn-sm" onclick="return confirm('Are you sure you want to kill process {{ pid }}?');">Kill</button>
                        </form>
                    </td>
                </tr>
                {{ end }}
            {{ else }}
            <tr>
                <td colspan="5" class="text-center">No processes found or unable to retrieve process list.</td>
            </tr>
            {{ end }}
        </tbody>
    </table>
</div>
{{ end }}

{{ block scripts() }}
<!-- Add any page-specific scripts here if needed -->
{{ end }}