{% extends "add-edit-main.html" %}
{%load static%}
{% block content %}

<div class="w-full px-5 s:px-9 mb-5">
    <div class="w-full h-full shadow-md rounded-md py-5 px-3 bg-white">
        <h1 class="text-3xl text-secondosiblue text-center font-semibold">
            Edit Project
        </h1>

        <form class="w-full flex flex-col gap-5 justify-center items-center" method="POST"
            action="{% url 'editproject' project.project_id %}">
            {% csrf_token %}
                <div class="w-full">
                    <label class="text-gray-500">Name:</label>
                    <input required name="name" type="text"
                    value="{{project.name}}"
                    class="w-full h-[50px] py-1 px-3 border border-gray-300 outline-none rounded-md mt-1">
                </div>

            <div class="w-full">
                <label class="text-gray-500">Client:</label>
                <select required name="customer"
                    class="w-full h-[50px] py-1 px-3 border border-gray-300 outline-none rounded-md text-gray-500 mt-1">
                    <option value="" disabled>Clients</option>
                    {% for customer in customers %}
                    <option value="{{customer.id}}" {% if customer.id == current_client.id %} selected {%endif%}>{{customer.user.first_name}} {{customer.user.last_name}}</option>
                    {% endfor %}
                </select>
            </div>

            <div class="w-full">
                <label class="text-gray-500">Project Manager:</label>
                <select required name="manager"
                    class="w-full h-[50px] py-1 px-3 border border-gray-300 outline-none rounded-md text-gray-500 mt-1">
                    <option value="" disabled>Project Manager</option>
                    {% for staff in staffs %}
                    <option value="{{staff.id}}" {% if staff.id == current_manager.id %} selected {%endif%}>{{staff.user.first_name}} {{staff.user.last_name}}</option>
                    {% endfor %}
                </select>
            </div>


            <div class="w-full">
                <label class="text-gray-500">Member(s):</label>
                <select required name="members" id=""
                    class="w-full h-[100px] py-1 px-3 border border-gray-300 outline-none rounded-md text-gray-500 mt-1"
                    multiple>
                    {% for staff in staffs %}
                        {% if staff in project.members.all %}
                         <option value="{{staff.id}}" selected>{{staff.user.first_name}} {{staff.user.last_name}}</option>
                        {% else %}
                         <option value="{{staff.id}}">{{staff.user.first_name}} {{staff.user.last_name}}</option>
                        {% endif %}
                    {% endfor %}
                </select>
            </div>

            <div class="w-full">
                <label class="text-gray-500">Type(s):</label>
                <select required name="types" id=""
                    class="w-full h-[100px] py-1 px-3 border border-gray-300 outline-none rounded-md text-gray-500 mt-1"
                    multiple>
                    {% for type in types %}
                        <option value="{{type.id}}"  {% if type in project.project_type.all %} selected {% endif %} >{{type.name}}</option>
                    {% endfor %}
                </select>
            </div>

            <div class="w-full">
                <label class="text-gray-500">Description:</label>
                <textarea required name="details" type="text" rows="5" cols="5"
                    class="w-full py-3 px-3 border border-gray-300 outline-none rounded-md resize-none mt-1">{{project.details}}
                </textarea>
            </div>

            <div class="w-full">
                <label class="text-gray-500">Start Date:</label>
                <input required name="start_date" type="date"  id="startDateDisplay" name="date"
                value='{{project.start_date|date:"Y-m-d"}}'
                class="w-full p-3 border border-gray-300 rounded-md bg-transparent outline-none mt-1">
            </div>


            <div class="w-full">
                <label class="text-gray-500">End Date:</label>
                <input required name="end_date" type="date" id="closingDateDisplay" name="date"
                value='{{project.end_date|date:"Y-m-d"}}'
                class="w-full p-3 border border-gray-300 rounded-md bg-transparent outline-none mt-2">
            </div>


            <script>
                const startDatePicker = document.getElementById('startDate');
                const startDateDisplay = document.getElementById('startDateDisplay');
                const closingDatePicker = document.getElementById('closingDate');
                const closingDateDisplay = document.getElementById('closingDateDisplay');
                // Adding an input event listener to the starting date picker input
                startDatePicker.addEventListener('input', () => {
                    // When a date is selected, update the value of the starting date display input
                    startDateDisplay.value = startDatePicker.value;
                });

                closingDatePicker.addEventListener('input', () => {
                    closingDateDisplay.value = closingDatePicker.value;
                });

                drawDatePicker.addEventListener('input', () => {
                    drawDateDisplay.value = drawDatePicker.value;
                });
            </script>

            <div class="w-full flex justify-center items-center mt-4">
                <button type="submit"
                    class="w-fit bg-osiblue border border-osiblue rounded-md text-white text-xl px-5 py-1 hover:bg-white hover:text-osiblue duration-300">Save</button>
            </div>
        </form>
    </div>
</div>


{% endblock content %}