{% extends 'service_partner_app/base_service_partner.html' %}
{% load static %}
{% block title %}Edit Service Partner Profile{% endblock %}

{% block content %}
<section class="py-5">
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-lg-9">
                <div class="card shadow-sm border-0 rounded-4">
                    <div class="card-body p-4 p-lg-5">
                        <h2 class="mb-4">Edit Profile</h2>

                        <form method="post" enctype="multipart/form-data">
                            {% csrf_token %}

                            <div class="row g-3">
                                {% for field in form %}
                                    <div class="{% if field.name == 'address' or field.name == 'about_me' or field.name == 'experience_summary' or field.name == 'skills' or field.name == 'resume_or_bio_data' %}col-12{% else %}col-md-6{% endif %}">
                                        <label class="form-label" for="{{ field.id_for_label }}">
                                            {{ field.label }}
                                        </label>

                                        {{ field }}

                                        {% if field.name == 'resume_or_bio_data' and partner.resume_or_bio_data %}
                                            <div class="mt-2 small">
                                                <strong>Current file:</strong>
                                                <a href="{{ partner.resume_or_bio_data.url }}"
                                                   target="_blank"
                                                   class="text-decoration-none">
                                                    View uploaded resume / biodata
                                                </a>
                                            </div>
                                        {% endif %}

                                        {% if field.help_text %}
                                            <small class="text-muted d-block mt-1">
                                                {{ field.help_text }}
                                            </small>
                                        {% endif %}

                                        {% for error in field.errors %}
                                            <div class="text-danger small mt-1">
                                                {{ error }}
                                            </div>
                                        {% endfor %}
                                    </div>
                                {% endfor %}
                            </div>

                            <div class="mt-4 d-flex gap-2 flex-wrap">
                                <button type="submit" class="btn btn-primary">
                                    Save Changes
                                </button>

                                <a href="{% url 'service_partner_app:service_partner_profile_page' %}"
                                   class="btn btn-outline-secondary">
                                    Cancel
                                </a>
                            </div>

                            {% if form.non_field_errors %}
                                <div class="alert alert-danger mt-3 mb-0">
                                    {% for error in form.non_field_errors %}
                                        <div>{{ error }}</div>
                                    {% endfor %}
                                </div>
                            {% endif %}
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
{% endblock %}