{% extends "base.html" %}
{% block title %}Network — SimpleX Manager{% endblock %}

{% block head %}
<style>
  .srv-table td { padding: 6px 12px; }
  .srv-host { font-family: monospace; font-size: 12px; }
  .srv-off { opacity: 0.5; }
  .op-sub { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px;
            color: var(--muted); margin: 14px 0 6px; }
  .net-table td:first-child { color: var(--muted); width: 45%; }
</style>
{% endblock %}

{% block content %}
<h1>Network</h1>

{% if not detail.profile_name %}
<div class="card" style="text-align:center;padding:48px;color:var(--muted);">
  No running profile. Start a profile to view SMP/XFTP servers and network status.
</div>
{% else %}
<p class="muted" style="margin-bottom:16px;">
  Servers and network config for <strong>{{ detail.profile_name }}</strong> (SimpleX presets are shared across profiles).
</p>

{% if detail.network %}
<div class="card">
  <h2>Network configuration</h2>
  <table class="net-table">
    <tr><td>SMP proxy mode</td><td>{{ detail.network.smpProxyMode | default('—', true) }}</td></tr>
    <tr><td>SMP proxy fallback</td><td>{{ detail.network.smpProxyFallback | default('—', true) }}</td></tr>
    <tr><td>Host mode</td><td>{{ detail.network.hostMode | default('—', true) }}</td></tr>
    <tr><td>Required host mode</td><td>{{ detail.network.requiredHostMode | default('—', true) }}</td></tr>
    <tr><td>Session mode</td><td>{{ detail.network.sessionMode | default('—', true) }}</td></tr>
    <tr><td>TCP connect timeout</td><td>{{ detail.network.tcpConnectTimeout | default('—', true) }}</td></tr>
  </table>
</div>
{% endif %}

{% for op in detail.operators %}
<div class="card">
  <div class="flex-between" style="margin-bottom:6px;">
    <h2 style="margin:0;">{{ op.name }}</h2>
    <span class="badge {% if op.enabled %}badge-green{% else %}badge-red{% endif %}">
      {{ 'enabled' if op.enabled else 'disabled' }}
    </span>
  </div>

  <div class="op-sub">SMP — messaging ({{ op.smp | length }})</div>
  {% if op.smp %}
  <table class="srv-table">
    {% for s in op.smp %}
    <tr class="{% if not s.enabled or s.deleted %}srv-off{% endif %}">
      <td class="srv-host">{{ s.host }}</td>
      <td style="text-align:right;">
        {% if s.preset %}<span class="tag">preset</span>{% endif %}
        {% if s.deleted %}<span class="badge badge-red">deleted</span>
        {% elif s.enabled %}<span class="badge badge-green">on</span>
        {% else %}<span class="badge badge-red">off</span>{% endif %}
      </td>
    </tr>
    {% endfor %}
  </table>
  {% else %}<p class="muted">None.</p>{% endif %}

  <div class="op-sub">XFTP — files ({{ op.xftp | length }})</div>
  {% if op.xftp %}
  <table class="srv-table">
    {% for s in op.xftp %}
    <tr class="{% if not s.enabled or s.deleted %}srv-off{% endif %}">
      <td class="srv-host">{{ s.host }}</td>
      <td style="text-align:right;">
        {% if s.preset %}<span class="tag">preset</span>{% endif %}
        {% if s.deleted %}<span class="badge badge-red">deleted</span>
        {% elif s.enabled %}<span class="badge badge-green">on</span>
        {% else %}<span class="badge badge-red">off</span>{% endif %}
      </td>
    </tr>
    {% endfor %}
  </table>
  {% else %}<p class="muted">None.</p>{% endif %}
</div>
{% endfor %}
{% endif %}
{% endblock %}
