{% extends 'base.html' %}
{% block title %}
    Applicants
{% endblock %}
{% load static %}
{% block styles %}

    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.3.200/pdf_viewer.css"/>
    <link rel="stylesheet" href="{% static 'vendor/font-awesome/css/font-awesome.min.css' %}"/>

    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .top-bar {
            background: #333;
            color: #fff;
            padding: 1rem;
        }

        .btn-pdf {
            background: coral;
            color: #fff;
            border: none;
            outline: none;
            cursor: pointer;
            padding: 0.7rem 2rem;
        }

        .btn-pdf:hover {
            opacity: 0.9;
        }

        .page-info {
            margin-left: 1rem;
        }

        .error {
            background: orangered;
            color: #fff;
            padding: 1rem;
        }
    </style>

{% endblock %}

{% block content %}

    <section class="bg-light-gray">
        <div class="container">
            <div class="row">
                <div class="col-lg-8 mx-auto">
                    <h1 class="heading">{{ applicant.user.get_full_name }}</h1>
                    <h6 class="heading">Applied for: {{ applicant.job.title }}</h6>
                </div>
            </div>
        </div>
    </section>
    <section>
        <div class="container">
            <div class="row">
                <div class="col-lg-8">
                    {% if applicant.cv.name %}
                        <div class="top-bar hidden">
                            <button class="btn btn-pdf" id="prev-page">
                                <i class="fa fa-arrow-circle-left"></i> Prev Page
                            </button>
                            <button class="btn btn-pdf" id="next-page">
                                Next Page <i class="fa fa-arrow-circle-right"></i>
                            </button>
                            <span class="page-info">
                            Page <span id="page-num"></span> of <span id="page-count"></span>
                        </span>
                        </div>

                        <canvas id="pdf-render"></canvas>
                    {% else %}
                        <h3>CV not available</h3>
                    {% endif %}
                </div>
                <div class="col-lg-4">
                    <h4>About: {{ applicant.user.get_full_name }}</h4>
                    <h6>Skills:
                        {% for tag in applicant.user.profile.tags.all %}
                            <span style="color: #ffffff;"
                                  class="badge featured-badge badge-secondary">{{ tag.name }}
                            </span>
                        {% endfor %}
                    </h6>
                    <h6>Gender: {{ applicant.user.gender }}</h6>
                    <h6>Email: {{ applicant.user.email }}</h6>
                    <h6 class="text-success">Status: {% if applicant.status == 1 %}
                        Pending {% elif applicant.status == 2 %} Accepted {% elif applicant.status == 3 %}
                        Rejected {% endif %}</h6>
                    <p class="job-detail__company-description">{{ job.company_description }}</p>
                    <p class="job-detail__social social social--outline">
                        <a href="{{ job.website }}" data-toggle="tooltip" data-placement="top" title="Website"
                           class="link">
                            <i class="fa fa-link"></i>
                        </a>
                    </p>
                    <input type="button" class="btn btn-outline-white-primary" {% if applicant.status != 1 %}
                           disabled {% endif %} value="Send Response" data-toggle="modal"
                           data-target="#myModal"/>
                </div>
                {% if applicant.status == 1 %}
                    <div class="modal fade" id="myModal">
                        <div class="modal-dialog">
                            <div class="modal-content">

                                <div class="modal-header">
                                    <h4 class="modal-title">Send response</h4>
                                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                                </div>

                                <form action="{% url 'jobs:applicant-send-response' applicant.id %}" method="POST">
                                    {% csrf_token %}
                                    <div class="modal-body">
                                        <input type="hidden" name="job_id" value="{{ applicant.job.id }}">
                                        <div class="form-group">
                                            <label for="status">Status</label>
                                            <select id="status" name="status" class="form-control">
                                                <option value="2" {% if applicant.status == 2 %} selected
                                                        disabled {% endif %}>
                                                    Accepted
                                                </option>
                                                <option value="3" {% if applicant.status == 3 %} selected
                                                        disabled {% endif %}>
                                                    Rejected
                                                </option>
                                            </select>
                                        </div>
                                        <div class="form-group">
                                            <label for="Comment">Comment</label>
                                            <textarea id="Comment" name="comment" rows="3" required
                                                      class="form-control">{{ applicant.comment|default_if_none:"" }}</textarea>
                                        </div>
                                    </div>

                                    <div class="modal-footer">
                                        <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
                                        <input type="submit" class="btn btn-success" value="Send"/>
                                    </div>
                                </form>

                            </div>
                        </div>
                    </div>
                {% endif %}
            </div>
        </div>
    </section>

{% endblock %}
