{% extends "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 mt-5 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">Status:</label>
                <select required name="status" 
                    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>Select Status</option>
                    <option value="Pending" {% if project.status == 'Pending' %} selected {%endif%}>Pending</option>
                    <option value="Active" {% if project.status == 'Active' %} selected {%endif%}>Active</option>
                    <option value="Completed" {% if project.status == 'Completed' %} selected {%endif%}>Completed</option>
                    <option value="Cancelled" {% if project.status == 'Cancelled' %} selected {%endif%}>Cancelled</option>
                </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 %}
                      {% if type in project.project_type.all %}
                       <option value="{{type.id}}" selected>{{type.name}}</option>
                      {%else%}
                        <option value="{{type.id}}" >{{type.name}}</option>
                      {% endif %}
                    {% 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">Lorem ipsum dolor sit amet consectetur adipisicing elit. Illum magnam ea temporibus commodi aspernatur culpa totam similique voluptate veritatis? Odit, excepturi? Itaque suscipit libero iure corrupti consequatur soluta expedita quod?
                </textarea>
            </div>

            <div class="w-full">
                <label class="text-gray-500">Start Date:</label>
                <input required name="start_date" type="date" id="date" name="date"
                value="2023-09-22"
                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="date" name="date"
                value="2023-10-22"
                class="w-full p-3 border border-gray-300 rounded-md bg-transparent outline-none mt-2">
            </div>

            <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>
</div>
<!-- POPUP MODAL -->
<div class="w-full h-full bg-black bg-opacity-40 z-20 fixed justify-center items-center hidden" id="popUpModal">
    <div class="w-[95%] md:w-fit h-fit bg-white rounded-md p-9 relative">
        <button class="absolute top-3 right-5 text-slate-800 text-xl cursor-pointer outline-none border-none"
            id="closeModalButton">
            <i class="fa fa-close"></i>
        </button>
        <iframe id="popupModalFrame" frameborder="0"></iframe>
    </div>
</div>

<script type="text/javascript" src='{% static "js/pop-modals.js" %}'></script>
</div>

{% endblock content %}