{% extends "base.html" %}

{% block title %}{{ bot.name }} - irc.bot{% endblock %}

{% block content %}
<div class="content">
  <div class="bot-header">
    <h1>{{ bot.name }}</h1>
    <span class="status status-{{ bot.status }}">{{ bot.status }}</span>
    {% if !status_message.is_empty() %}
    <span class="status-msg">{{ status_message }}</span>
    {% endif %}
  </div>

  <div class="actions">
    {% if running %}
    <form method="post" action="/{{ bot_id }}/stop" class="inline-form">
      <button type="submit" class="btn-outline">stop</button>
    </form>
    {% else %}
    <form method="post" action="/{{ bot_id }}/start" class="inline-form">
      <button type="submit" class="btn-fill">start</button>
    </form>
    {% endif %}
    <a href="/{{ bot_id }}/logs" class="btn-outline">logs</a>
    <a href="/{{ bot_id }}/kv" class="btn-outline">kv store</a>
    <form method="post" action="/{{ bot_id }}/delete" class="inline-form"
          onsubmit="return confirm('delete this bot?')">
      <button type="submit" class="btn-outline delete-btn">delete</button>
    </form>
  </div>

  <div class="tabs">
    <div class="tab-section">
      <h2>config</h2>
      <form method="post" action="/{{ bot_id }}/update" class="bot-form">
        <label>name</label>
        <input type="text" name="name" value="{{ bot.name }}" class="input" required>

        <label>nick</label>
        <input type="text" name="nick" value="{{ bot.nick }}" class="input" required>

        <label>network address</label>
        <input type="text" name="network_addr" value="{{ bot.network_addr }}" class="input" required>

        <label>sasl username</label>
        <input type="text" name="sasl_username" value="{{ sasl_username }}" class="input">

        <label>sasl password</label>
        <input type="password" name="sasl_password" placeholder="(unchanged)" class="input">

        <label>channels (comma separated)</label>
        <input type="text" name="channels" value="{{ channels }}" class="input">

        <button type="submit" class="btn-fill">save config</button>
      </form>
    </div>

    <div class="tab-section">
      <h2>scripts</h2>
      {% if scripts.is_empty() %}
      <p>no scripts yet.</p>
      {% else %}
      <table class="table">
        <thead>
          <tr>
            <th>name</th>
            <th>enabled</th>
            <th></th>
          </tr>
        </thead>
        <tbody>
          {% for s in scripts %}
          <tr>
            <td><a href="/{{ bot_id }}/scripts/{{ s.id }}">{{ s.name }}</a></td>
            <td>{% if s.enabled %}yes{% else %}no{% endif %}</td>
            <td>
              <form method="post" action="/{{ bot_id }}/scripts/{{ s.id }}/delete" class="inline-form">
                <button type="submit" class="link-btn delete-btn">delete</button>
              </form>
            </td>
          </tr>
          {% endfor %}
        </tbody>
      </table>
      {% endif %}
      <a href="/{{ bot_id }}/scripts/create" class="btn-outline">new script</a>
    </div>
  </div>
</div>
{% endblock %}
