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


<div class="w-full xxlg1:w-[75%] bg-white h-fit rounded-md shadow-md p-5">

    <div
        class="w-full rounded-md flex flex-col justify-center items-center py-3  {% if task.status == 'Open' %} bg-osiblue {% endif %}  {% if task.status == 'Working On' %} bg-yellow-500 {% endif %}  {% if task.status == 'Closed' %} bg-green-700 {% endif %} bg-opacity-70">
        <h1 class="text-xl md:text-3xl text-white font-semibold text-center">{{task.name}}</h1>
    </div>

    <div class="w-full h-fit flex flex-col md:flex-row gap-3 justify-between items-center bg-gray-100 shadow-md rounded-md px-3 py-3 mt-4">
        <div class="flex justify-start items-center gap-2">
            <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
                stroke="currentColor" class="w-6 h-6 text-secondosiblue">
                <path stroke-linecap="round" stroke-linejoin="round"
                    d="M12 6v6h4.5m4.5 0a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z" />
            </svg>

            <p class="text-secondosiblue">Total Time: <span class="font-poppinsBold">{{ task.total_task_time.0 }}
                {% if task.total_task_time.0 == 1 %}hr{% else %}hrs{% endif %} {{ task.total_task_time.1 }}
                {% if task.total_task_time.1 == 1 %}min{% else %}mins{% endif %} {{ task.total_task_time.2 }} 
                {% if task.total_task_time.2 == 1 %}sec{% else %}secs{% endif %}</span></p>

        </div>

        <div class="w-full s:w-fit flex flex-col s:flex-row justify-end items-center gap-3">
            <button
                class="w-full s:w-fit text-base px-3 py-2 bg-red-500 text-white outline-none border border-red-500 rounded-md cursor-pointer hover:bg-white hover:text-red-500 duration-300 deleteTaskButton"
                data-modal-url="{% url 'deletetaskmodal' task.id %}">Delete
                Task</button>
            <a href="{% url 'edittask' task.task_id %}" class="w-full s:w-fit">
                <button
                    class="w-full s:w-fit text-base px-3 py-2 bg-fifthosiblue text-white outline-none border border-fifthosiblue rounded-md cursor-pointer hover:bg-white hover:text-fifthosiblue duration-300">Edit
                    Task</button>
            </a>
        </div>
    </div>


    <div class="w-full flex flex-col gap-5 mt-5">

        <div>
            <p class="text-gray-500 text-xl">Description: <span
                    class="text-slate-800 text-xl font-semibold">{{task.description}}</span></p>
        </div>


        <div>
            <p class="text-gray-500 text-xl">Project: <span
                    class="text-slate-800 text-xl font-semibold">{{task.project.name}}</span></p>
        </div>

        <div>
            <p class="text-gray-500 text-xl">Epic: <span
                    class="text-slate-800 text-xl font-semibold">{{task.epic.title}}</span></p>
        </div>

        <div>
            <p class="text-gray-500 text-xl">Start Date: <span
                    class="text-slate-800 text-xl font-semibold">{{task.start_date}}</span></p>
        </div>

        <div>
            <p class="text-gray-500 text-xl">End Date: <span
                    class="text-slate-800 text-xl font-semibold">{{task.end_date}}</span></p>
        </div>


        <div>
            <p class="text-gray-500 text-xl">Assigned To: <span
                    class="text-slate-800 text-xl font-semibold">{{task.assigned_to.user.first_name}}
                    {{task.assigned_to.user.last_name}}</span></p>
        </div>

        <div>
            <p class="text-gray-500 text-xl">Extra: <span
                    class="text-slate-800 text-xl font-semibold">{{task.extra}}</span></p>
        </div>

        <div>
            <p class="text-gray-500 text-xl">Status:
                {% if task.status == 'Closed' %}
                <span class="text-green-700 text-xl font-semibold">{{task.status}}</span>
                {% endif %}
                {% if task.status == 'Open' %}
                <span class="text-osiblue text-xl font-semibold">{{task.status}}</span>
                {% endif %}
                {% if task.status == 'Working On' %}
                <span class="text-yellow-500 text-xl font-semibold">{{task.status}}</span>
                {% endif %}
            </p>
        </div>

        <div>
            <p class="text-gray-500 text-xl">Related Files: <span class="text-slate-800 text-xl">Documentation.pdf,
                    Project.doc</span>
            </p>
        </div>

        <!-- TAGS -->
        <div>
            <p class="text-gray-500 text-xl">Tags:</p>
            <div class="w-full h-fit mt-3 flex flex-wrap justify-start items-center gap-3">
                <button
                    class="text-sm text-gray-400 border border-gray-400 rounded-md w-fit py-2 px-3 outline-none cursor-pointer">Media
                    Streaming</button>

                <button
                    class="text-sm text-gray-400 border border-gray-400 rounded-md w-fit py-2 px-3 outline-none cursor-pointer">Live
                    Streaming</button>

                <button
                    class="text-sm text-gray-400 border border-gray-400 rounded-md w-fit py-2 px-3 outline-none cursor-pointer">Audio
                    On Demand</button>
            </div>
        </div>


        <!-- POINTS -->
        <div class="mt-5 relative">
            <div
                class=" bg-gray-200 rounded-t-md flex justify-between items-center text-white text-xl font-bold h-[50px]">
                <div class="px-3">
                    <p class="text-secondosiblue uppercase font-bold">Points</p>
                </div>

                <button
                    class="h-full rounded-tr-md px-4 bg-secondosiblue text-gray-200 text-[18px] outline-none border-none cursor-pointer flex justify-center items-center addPointButton"
                    data-modal-url="{% url 'addpointmodal' task.task_id %}">
                    <i class="fa fa-plus"></i>
                </button>
            </div>

            <div>
                {% if points %}
                {% for point in points %}
                <p class="pointId" data-point-id="{{ point.id }}" style="display: none;">{{ point.id }}</p>
                <div class="w-full flex flex-col gap-1 
                        {% if point.status == 'Completed' %}
                            bg-green-700
                        {% elif point.status == 'Working On' %}
                                bg-orange-500
                        {% elif point.status == 'Paused' %}
                                bg-red-500
                        {% else %}
                                bg-slate-700
                        {% endif %}
                         bg-opacity-50 rounded-md shadow-md p-3 mt-4">
                    <div class="w-full flex justify-between items-end pb-2 border-b border-gray-200">
                        <div class="w-[380px]">
                            {% if point.status == 'Completed' %}
                            <p class="text-white line-through">{{point.text}}</p>
                            {% else %}
                            <p class="text-white">{{point.text}}</p>
                            {% endif %}
                        </div>

                        <div class="flex justify-end items-center gap-2">
                            {% if point.status == 'Not Completed' or point.status == 'Paused' and not point.status == 'Completed' %}
                            <a href="{% url 'mark_point_working_on_task_page' point.id task.id %}">
                                <button
                                    class="w-[40px] h-[40px] rounded-full bg-transparent shadow-md text-white border border-white flex justify-center items-center hover:scale-105 transition-transform duration-300"
                                    id="startPointButton">
                                    <i class="fa fa-play"></i>
                                </button>
                            </a>
                            {% endif %}

                            {% if point.status == 'Working On' and not point.status == 'Completed' %}
                            <a href="{% url 'mark_point_paused_task_page' point.id task.id %}">
                                <button
                                    class="w-[40px] h-[40px] rounded-full bg-transparent shadow-md text-white border border-white justify-center items-center hover:scale-105 transition-transform duration-300"
                                    id="pausePointButton">
                                    <i class="fa fa-pause"></i>
                                </button>
                            </a>
                            {% endif %}

                            {% if not point.status == 'Completed' and not point.status == 'Paused' %}
                            <a href="{% url 'mark_point_completed_task_page' point.id task.id %}">
                                <button
                                    class="w-[40px] h-[40px] rounded-full bg-transparent shadow-md text-white border border-white flex justify-center items-center hover:scale-105 transition-transform duration-300">
                                    <i class="fa fa-check"></i>
                                </button>
                            </a>
                            {% endif %}


                            {% if point.status == 'Completed' %}
                            <button
                                class="w-[40px] h-[40px] rounded-full bg-transparent shadow-md text-white border border-white flex justify-center items-center opacity-30 cursor-default">
                                <i class="fa fa-check"></i>
                            </button>
                            {% endif %}

                            {% if not point.status == 'Completed' %}
                            <form method="post" action="{% url 'deletepointmodal' point.id task.id %}">
                                {% csrf_token %}
                                <button type="submit"
                                    class="w-[40px] h-[40px] bg-transparent border border-white rounded-full text-white flex justify-center items-center shadow-md hover:scale-105 transition-transform duration-300">
                                    <i class="fa fa-trash"></i>
                                </button>
                            </form>
                            {% endif %}
                        </div>
                    </div>

                    <div class="flex justify-between items-center gap-3 pt-2">
                        <div class="text-white text-sm">
                            <p>Total Time:
                                <span class="font-semibold pointTotalTime">
                                    <span class="hours">{{ point.total_activity_time.0 }}</span> hours,
                                    <span class="minutes">{{ point.total_activity_time.1 }}</span> minutes,
                                    <span class="seconds">{{ point.total_activity_time.2 }}</span> seconds
                                </span>
                            </p>
                        </div>

                        <div class="w-fit py-1 px-2 bg-white text-secondosiblue text-xs rounded-md shadow-md">
                            {% if point.status == 'Completed' %}
                            <p class="text-green-700 opacity-50">Completed</p>
                            {% elif point.status == 'Working On' %}
                            <p class="text-orange-500 opacity-50">Working On</p>
                            {% elif point.status == 'Paused' %}
                            <p class="text-red-500 opacity-50">Paused</p>
                            {% else %}
                            <p class="text-secondosiblue opacity-50">Created</p>
                            {% endif %}
                        </div>
                    </div>
                </div>
                {% endfor %}
                {% else %}
                <div class="w-full flex justify-center items-center p-5 text-secondosiblue text-center">
                    <p>No Available Points</p>
                </div>
                {% endif %}
            </div>
        </div>

    </div>
</div>



{% endblock content %}