{% extends 'base.html' %}
{% load i18n %}

{% block content %}
<div class="container-fluid">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h1 class="h3 text-gray-800">{{ title }}</h1>
        <a href="{% url 'hr:device_list' %}" class="btn btn-secondary">
            <i class="bi bi-arrow-left"></i> {% trans "Back to List" %}
        </a>
    </div>

    <div class="card shadow mb-4">
        <div class="card-body">
            <form method="post">
                {% csrf_token %}
                <div class="row">
                    <div class="col-md-6 mb-3">
                        <label class="form-label">{% trans "Device Name" %}</label>
                        <input type="text" name="name" class="form-control" value="{{ form.name.value|default:'' }}" required>
                        {% if form.name.errors %}
                            <div class="text-danger small">{{ form.name.errors }}</div>
                        {% endif %}
                    </div>
                    <div class="col-md-6 mb-3">
                        <label class="form-label">{% trans "IP Address" %}</label>
                        <input type="text" name="ip_address" class="form-control" value="{{ form.ip_address.value|default:'' }}" required placeholder="192.168.1.201">
                        {% if form.ip_address.errors %}
                            <div class="text-danger small">{{ form.ip_address.errors }}</div>
                        {% endif %}
                    </div>
                    <div class="col-md-4 mb-3">
                        <label class="form-label">{% trans "Port" %}</label>
                        <input type="number" name="port" class="form-control" value="{{ form.port.value|default:'4370' }}" required>
                        {% if form.port.errors %}
                            <div class="text-danger small">{{ form.port.errors }}</div>
                        {% endif %}
                    </div>
                    <div class="col-md-4 mb-3">
                        <label class="form-label">{% trans "Device Type" %}</label>
                        <select name="device_type" class="form-select">
                            {% for code, name in form.fields.device_type.choices %}
                                <option value="{{ code }}" {% if form.device_type.value == code %}selected{% endif %}>{{ name }}</option>
                            {% endfor %}
                        </select>
                    </div>
                     <div class="col-md-4 mb-3">
                        <label class="form-label">{% trans "Status" %}</label>
                        <select name="status" class="form-select">
                            {% for code, name in form.fields.status.choices %}
                                <option value="{{ code }}" {% if form.status.value == code %}selected{% endif %}>{{ name }}</option>
                            {% endfor %}
                        </select>
                    </div>
                </div>
                <button type="submit" class="btn btn-primary">{% trans "Save Device" %}</button>
            </form>
        </div>
    </div>
</div>
{% endblock %}