{% extends "layouts/base.html" %}
{% load i18n %}

{% block title %}{% if source %}{% trans "Edit Source" %}{% else %}{% trans "Create Source" %}{% endif %}{% endblock %}

{% block content %}
<div class="container-fluid">
    <!-- Page Header -->
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <nav aria-label="breadcrumb">
                <ol class="breadcrumb mb-2">
                    <li class="breadcrumb-item">
                        <a href="{% url 'px_sources:source_list' %}">{% trans "PX Sources" %}</a>
                    </li>
                    <li class="breadcrumb-item active" aria-current="page">
                        {% if source %}{% trans "Edit Source" %}{% else %}{% trans "Create Source" %}{% endif %}
                    </li>
                </ol>
            </nav>
            <h2 class="mb-1">
                <i class="bi bi-{% if source %}pencil-square{% else %}plus-circle{% endif %} text-warning me-2"></i>
                {% if source %}{% trans "Edit Source" %}{% else %}{% trans "Create Source" %}{% endif %}
            </h2>
            {% if source %}
            <p class="text-muted mb-0">{{ source.name_en }}</p>
            {% endif %}
        </div>
        <div>
            <a href="{% url 'px_sources:source_list' %}" class="btn btn-outline-secondary">
                <i class="bi bi-arrow-left me-1"></i> {% trans "Back to List" %}
            </a>
        </div>
    </div>

    <!-- Form Card -->
    <div class="card">
        <div class="card-header">
            <h5 class="card-title mb-0">
                <i class="bi bi-form me-2"></i>{% trans "Source Information" %}
            </h5>
        </div>
        <div class="card-body">
            <form method="post" enctype="multipart/form-data">
                {% csrf_token %}
                
                <div class="row">
                    <div class="col-md-6">
                        <div class="mb-3">
                            <label for="name_en" class="form-label">
                                {% trans "Name (English)" %} <span class="text-danger">*</span>
                            </label>
                            <input type="text" class="form-control" id="name_en" name="name_en" 
                                   value="{{ source.name_en|default:'' }}" required
                                   placeholder="{% trans 'e.g., Patient Portal' %}">
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="mb-3">
                            <label for="name_ar" class="form-label">
                                {% trans "Name (Arabic)" %}
                            </label>
                            <input type="text" class="form-control" id="name_ar" name="name_ar" 
                                   value="{{ source.name_ar|default:'' }}" dir="rtl"
                                   placeholder="{% trans 'e.g., بوابة المرضى' %}">
                        </div>
                    </div>
                </div>

                <div class="mb-3">
                    <label for="description" class="form-label">
                        {% trans "Description" %}
                    </label>
                    <textarea class="form-control" id="description" name="description" 
                              rows="4" placeholder="{% trans 'Describe this source channel...' %}">{{ source.description|default:'' }}</textarea>
                    <small class="form-text text-muted">
                        {% trans "Optional: Additional details about this source" %}
                    </small>
                </div>

                <div class="mb-4">
                    <div class="form-check form-switch">
                        <input class="form-check-input" type="checkbox" id="is_active" name="is_active" 
                               {% if source.is_active|default:True %}checked{% endif %}>
                        <label class="form-check-label" for="is_active">
                            {% trans "Active" %}
                        </label>
                    </div>
                    <small class="form-text text-muted">
                        {% trans "Uncheck to deactivate this source (it won't appear in dropdowns)" %}
                    </small>
                </div>

                <div class="d-flex gap-2">
                    <button type="submit" class="btn btn-primary">
                        <i class="fas fa-save"></i> {% trans "Save" %}
                    </button>
                    <a href="{% url 'px_sources:source_list' %}" class="btn btn-secondary">
                        {% trans "Cancel" %}
                    </a>
                </div>
            </form>
        </div>
    </div>
</div>
{% endblock %}