{% load i18n %}
<form method="post"
      action="{% url 'projects:htmx_phase_edit_form' project_pk=project.pk phase_type=phase_type phase=phase_key %}"
      hx-post="{% url 'projects:htmx_phase_edit_form' project_pk=project.pk phase_type=phase_type phase=phase_key %}"
      hx-target="this"
      hx-swap="outerHTML"
      class="space-y-4"
      hx-on::after-request="if(event.detail.successful && !event.detail.xhr.response.includes('<form')) { closePhaseModal(); }">
    {% csrf_token %}
    
    <div class="grid grid-cols-2 gap-4">
        <div>
            <label class="block text-xs font-bold text-slate uppercase tracking-wider mb-1.5">{% trans "Phase Title" %}</label>
            <input type="text" name="title" value="{{ phase_obj.title }}" 
                   class="w-full px-4 py-2.5 bg-slate-50 border border-slate-200 rounded-xl text-sm focus:bg-white focus:border-navy focus:ring-2 focus:ring-navy/10 outline-none transition">
        </div>
        <div>
            <label class="block text-xs font-bold text-slate uppercase tracking-wider mb-1.5">{% trans "Status" %}</label>
            <select name="status" class="w-full px-4 py-2.5 bg-slate-50 border border-slate-200 rounded-xl text-sm focus:bg-white focus:border-navy focus:ring-2 focus:ring-navy/10 outline-none transition">
                {% for status_val, status_label in status_choices %}
                <option value="{{ status_val }}" {% if phase_obj.status == status_val %}selected{% endif %}>{{ status_label }}</option>
                {% endfor %}
            </select>
        </div>
    </div>

    <div>
        <label class="block text-xs font-bold text-slate uppercase tracking-wider mb-1.5">{% trans "Description" %}</label>
        <textarea name="description" rows="3" 
                  class="w-full px-4 py-2.5 bg-slate-50 border border-slate-200 rounded-xl text-sm focus:bg-white focus:border-navy focus:ring-2 focus:ring-navy/10 outline-none transition">{{ phase_obj.description }}</textarea>
    </div>

    <div class="grid grid-cols-3 gap-4">
        <div>
            <label class="block text-xs font-bold text-slate uppercase tracking-wider mb-1.5">{% trans "Owner" %}</label>
            <select name="owner" class="w-full px-4 py-2.5 bg-slate-50 border border-slate-200 rounded-xl text-sm focus:bg-white focus:border-navy focus:ring-2 focus:ring-navy/10 outline-none transition">
                <option value="">{% trans "Unassigned" %}</option>
                {% for member in team_members %}
                <option value="{{ member.pk }}" {% if phase_obj.owner_id == member.pk %}selected{% endif %}>{{ member.get_full_name }}</option>
                {% endfor %}
            </select>
        </div>
        <div>
            <label class="block text-xs font-bold text-slate uppercase tracking-wider mb-1.5">{% trans "Start Date" %}</label>
            <input type="date" name="start_date" value="{{ phase_obj.start_date|date:'Y-m-d' }}" 
                   class="w-full px-4 py-2.5 bg-slate-50 border border-slate-200 rounded-xl text-sm focus:bg-white focus:border-navy focus:ring-2 focus:ring-navy/10 outline-none transition">
        </div>
        <div>
            <label class="block text-xs font-bold text-slate uppercase tracking-wider mb-1.5">{% trans "Due Date" %}</label>
            <input type="date" name="due_date" value="{{ phase_obj.due_date|date:'Y-m-d' }}" 
                   class="w-full px-4 py-2.5 bg-slate-50 border border-slate-200 rounded-xl text-sm focus:bg-white focus:border-navy focus:ring-2 focus:ring-navy/10 outline-none transition">
        </div>
    </div>

    <div>
        <label class="block text-xs font-bold text-slate uppercase tracking-wider mb-1.5">{% trans "Findings" %}</label>
        <textarea name="findings" rows="3" 
                  class="w-full px-4 py-2.5 bg-slate-50 border border-slate-200 rounded-xl text-sm focus:bg-white focus:border-navy focus:ring-2 focus:ring-navy/10 outline-none transition"
                  placeholder="{% trans 'Key findings and observations...' %}">{{ phase_obj.findings }}</textarea>
    </div>

    <div class="flex items-center gap-3 pt-4 border-t border-slate-200">
        <button type="submit" class="px-4 py-2 bg-navy text-white rounded-xl text-sm font-bold hover:bg-blue transition flex items-center gap-2">
            <i data-lucide="save" class="w-4 h-4"></i> {% trans "Save Phase" %}
        </button>
        <button type="button" onclick="closePhaseModal()" class="px-4 py-2 border border-slate-200 text-slate rounded-xl text-sm font-bold hover:bg-slate-50 transition">
            {% trans "Cancel" %}
        </button>
    </div>
</form>
