{% extends "main.html" %}
{%load static%}
{% block title %}My Projects{% endblock %}
{% block content %}

<div class="w-full xxlg1:w-[75%]">
    <div class="w-full h-fit bg-white rounded-md shadow-md p-5">
        <h1 class="text-secondosiblue text-[30px] font-semibold">Customers</h1>

        <!-- FILTERING -->
        <div
            class="w-full py-4 px-3 bg-gray-200 rounded-md shadow-md mt-4 flex flex-col s:flex-row justify-between gap-3 items-center">
            <div class="w-full s:w-fit flex justify-start items-center gap-5">
                <div class="relative h-fit w-full s:w-fit flex items-center">
                    <input type="text" placeholder="Enter Customer Name"
                        class="py-2 px-3 border border-gray-300 rounded-md outline-none w-full s:w-[300px] h-[40px] relative">
                    <button
                        class="text-gray-500 text-xl outline-none border-none cursor-pointer absolute right-2 bg-white">
                        <i class="fa fa-search"></i>
                    </button>
                </div>
            </div>
            <div class="w-full s:w-fit">
                <a href="{% url 'addcustomer' %}" class="w-full s:w-fit">
                    <button
                        class="w-full s:w-fit text-base px-3 py-2 bg-osiblue text-white outline-none border border-osiblue rounded-md cursor-pointer hover:bg-white hover:text-osiblue duration-300">Add
                        Customer</button>
                </a>
            </div>
        </div>

        <div class="overflow-x-auto border border-gray-300 rounded-md mt-5" id="customersContainer">
            <table class="min-w-full divide-y">
                <!-- TABLE HEADER -->
                <thead class="bg-gray-50">
                    <tr>
                        <th scope="col"
                            class="px-6 py-3 text-sm font-medium text-gray-500 uppercase border-r border-gray-300 whitespace-nowrap">
                            Customer
                        </th>
                        <th scope="col"
                            class="px-6 py-3 text-sm font-medium text-gray-500 uppercase border-r border-gray-300 whitespace-nowrap">
                            User
                        </th>
                        <th scope="col"
                            class="px-6 py-3 text-sm font-medium text-gray-500 uppercase border-r border-gray-300 whitespace-nowrap">
                            Status
                        </th>
                        <th scope="col"
                            class="px-6 py-3 text-sm font-medium text-gray-500 uppercase border-r border-gray-300 whitespace-nowrap">
                            Business
                        </th>
                        <th scope="col" class="px-6 py-3 text-sm font-medium text-gray-500 uppercase whitespace-nowrap">
                            Actions
                        </th>
                    </tr>
                </thead>

                <!-- TABLE BODY -->
                <tbody class="bg-white divide-y divide-gray-200">
                    <!-- 1st row -->
                    {% for customer in customers %}
                    <tr>
                        <td class="px-6 py-4 text-center text-sm border-r border-gray-300">
                            <p class="text-slate-800">{{customer.user.first_name}}
                                {{customer.user.last_name}}</p>
                        </td>

                        <td class="px-6 py-4 text-center text-sm border-r border-gray-300">
                            <p class="text-slate-800">{{customer.user.username}}</p>
                        </td>

                        {% if customer.status == 'Active' %}
                        <td class="px-6 py-4 text-center text-sm border-r border-gray-300 bg-green-700">
                            <p class="text-white">{{customer.status}}</p>
                        </td>
                        {% endif %}

                        {% if customer.status == 'Terminated' %}
                        <td class="px-6 py-4 text-center text-sm border-r border-gray-300 bg-gray-500">
                            <p class="text-white">{{customer.status}}</p>
                        </td>
                        {% endif %}

                        {% if customer.status == 'Suspended' %}
                        <td class="px-6 py-4 text-center text-sm border-r border-gray-300 bg-red-500">
                            <p class="text-white">{{customer.status}}</p>
                        </td>
                        {% endif %}

                        <td class="px-6 py-4 text-center text-sm border-r border-gray-300">
                            <p class="text-slate-800">{{customer.business}}</p>
                        </td>

                        <td class="px-6 py-4 text-center text-sm">
                            <div class="w-full flex justify-center items-center gap-3">
                                <a href="{% url 'customerdetails' customer.customer_id  %}">
                                    <div class="text-[15px] text-blue-500 cursor-pointer">
                                        <i class="fa fa-eye"></i>
                                    </div>
                                </a>

                                <a href="{% url 'editcustomer' customer.customer_id %}">
                                    <div class="text-[15px] text-blue-500 cursor-pointer">
                                        <i class="fa fa-edit"></i>
                                    </div>
                                </a>

                                <div class="text-[15px] text-red-500 cursor-pointer deleteCustomerButton"
                                    data-modal-url="{% url 'deletecustomermodal' customer.id %}">
                                    <i class="fa fa-trash"></i>
                                </div>
                            </div>
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>

<!-- POPUP MODAL -->
<div class="w-full h-full bg-black bg-opacity-40 z-20 fixed justify-center items-center hidden inset-0" 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>


{% endblock content %}