{% extends "base.html" %}

{% block title %}{% if server %}Edit{% else %}Add{% endif %} Server - {{ lab_name }}{% endblock %}

{% block content %}
<div class="card" style="max-width: 600px; margin: 0 auto;">
    <div class="card-header">
        {% if server %}Edit Server{% else %}Add New Server{% endif %}
    </div>
    
    <form method="POST">
        <div class="form-group">
            <label for="hostname">Hostname</label>
            <input type="text" id="hostname" name="hostname" class="form-control" required
                   value="{% if server %}{{ server.hostname }}{% endif %}"
                   placeholder="server01.airex.iisc.ac.in">
        </div>
        
        <div class="form-group">
            <label for="ip_address">IP Address</label>
            <input type="text" id="ip_address" name="ip_address" class="form-control" required
                   value="{% if server %}{{ server.ip_address }}{% endif %}"
                   placeholder="localhost"
                   pattern="^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$">
        </div>
        
        <div class="form-group">
            <label for="admin_name">Administrator</label>
            <input type="text" id="admin_name" name="admin_name" class="form-control"
                   value="{% if server %}{{ server.admin_name }}{% endif %}"
                   placeholder="Admin name or contact">
        </div>
        
        <div class="form-group">
            <label for="location">Location</label>
            <input type="text" id="location" name="location" class="form-control"
                   value="{% if server %}{{ server.location }}{% endif %}"
                   placeholder="Room number, rack location, etc.">
        </div>
        
        <div class="form-group">
            <label for="description">Description</label>
            <textarea id="description" name="description" class="form-control" rows="4"
                      placeholder="Server purpose, specifications, etc.">{% if server %}{{ server.description }}{% endif %}</textarea>
        </div>
        
        <div style="display: flex; gap: 1rem; margin-top: 2rem;">
            <button type="submit" class="btn btn-primary">
                {% if server %}Update Server{% else %}Add Server{% endif %}
            </button>
            <a href="{{ url_for('inventory') }}" class="btn btn-secondary">Cancel</a>
        </div>
    </form>
</div>
{% endblock %}
