{% extends "base.html" %}

{% block title %}{{ action }} {% if check_type == "json-http" %}JSON HTTP{% else %}HTTP{% endif %} Health Check - Nyxmon Dashboard{% endblock %}

{% block content %}
<div class="form-container">
  <div class="form-header">
    {% if check_type == "json-http" %}
    <h2>📋 {{ action }} JSON HTTP Health Check</h2>
    {% else %}
    <h2>🌐 {{ action }} HTTP Health Check</h2>
    {% endif %}
    <a href="{% url 'nyxboard:healthcheck_list' %}" class="back-link">&larr; Back</a>
  </div>

  {% if check_type == "json-http" %}
  <p class="help-text">Monitor JSON API endpoint and validate response structure</p>
  {% else %}
  <p class="help-text">Monitor web endpoint availability and response</p>
  {% endif %}

  <form method="post" class="form">
    {% csrf_token %}

    <h3 class="section-title">Basic Information</h3>

    <div class="form-field">
      <label for="{{ form.name.id_for_label }}">{{ form.name.label }}</label>
      {{ form.name }}
      {% if form.name.help_text %}
        <div class="help-text">{{ form.name.help_text }}</div>
      {% endif %}
      {% if form.name.errors %}
        <div class="field-errors">
          {% for error in form.name.errors %}
            <div class="error">{{ error }}</div>
          {% endfor %}
        </div>
      {% endif %}
    </div>

    <div class="form-field">
      <label for="{{ form.service.id_for_label }}">{{ form.service.label }}</label>
      {{ form.service }}
      {% if form.service.errors %}
        <div class="field-errors">
          {% for error in form.service.errors %}
            <div class="error">{{ error }}</div>
          {% endfor %}
        </div>
      {% endif %}
    </div>

    <div class="form-field">
      <label for="{{ form.check_interval.id_for_label }}">{{ form.check_interval.label }}</label>
      {{ form.check_interval }}
      {% if form.check_interval.help_text %}
        <div class="help-text">{{ form.check_interval.help_text }}</div>
      {% endif %}
      {% if form.check_interval.errors %}
        <div class="field-errors">
          {% for error in form.check_interval.errors %}
            <div class="error">{{ error }}</div>
          {% endfor %}
        </div>
      {% endif %}
    </div>

    <div class="form-field checkbox-field">
      {{ form.disabled }}
      <label for="{{ form.disabled.id_for_label }}">{{ form.disabled.label }}</label>
      {% if form.disabled.help_text %}
        <div class="help-text">{{ form.disabled.help_text }}</div>
      {% endif %}
    </div>

    <h3 class="section-title">{% if check_type == "json-http" %}JSON HTTP{% else %}HTTP{% endif %} Configuration</h3>

    <div class="form-field">
      <label for="{{ form.url.id_for_label }}">{{ form.url.label }}</label>
      {{ form.url }}
      {% if form.url.help_text %}
        <div class="help-text">{{ form.url.help_text }}</div>
      {% endif %}
      {% if form.url.errors %}
        <div class="field-errors">
          {% for error in form.url.errors %}
            <div class="error">{{ error }}</div>
          {% endfor %}
        </div>
      {% endif %}
    </div>

    {{ form.check_type }}

    <div class="form-actions">
      <button type="submit" class="btn btn-success">{{ action }}</button>
      <a href="{% url 'nyxboard:healthcheck_list' %}" class="btn btn-secondary">Cancel</a>
    </div>
  </form>
</div>
{% endblock %}
