{% extends 'base.html' %}
{% load static %}
{% load is_already_applied %}
{% load humanize %}
{% block title %}
    Job details
{% endblock %}

{% block content %}

    <section class="bg-light-gray">
        <div class="container">
            <h1 class="heading">{{ job.title }}<br>
                <small>at <a href="#"> {{ job.company_name }}</a></small>
            </h1>
            <div class="job-detail-description"><i class="fa fa-map-marker job__location"> </i>
                {{ job.location }} | Posted {{ job.created_at|timesince }} ({{ job.created_at }}) |
                {% if job.type == '1' %}
                    <span class="badge featured-badge badge-success">Full time</span>
                {% elif job.type == '2' %}
                    <span class="badge featured-badge badge-primary">Part time</span>
                {% else %}
                    <span style="color: #ffffff;" class="badge featured-badge badge-warning">Internship</span>
                {% endif %}
            </div>
        </div>
    </section>
    <section>
        <div class="container">
            <div class="row">
                <div class="col-lg-8">
                    <h3>Category: {{ job.category }}</h3>
                    <h5>Last date: {{ job.last_date|date }}</h5>
                    <h5 style="color: blueviolet;">Vacancy: {{ job.vacancy }}</h5>
                    <h5 class="text-info">
                        Salary: {% if job.salary > 0 %} {{ job.salary | intcomma }}/Monthly {% else %}
                        Negotiable {% endif %}
                    </h5>
                    Tags:
                    {% for tag in job.tags.all %}
                        <span style="color: #ffffff;" class="badge featured-badge badge-secondary">{{ tag.name }}</span>
                    {% endfor %}
                    <blockquote class="blockquote">
                        <p>{{ job.description | safe }}</p>
                    </blockquote>
                    <div class="job-detail__apply-bottom">
                        {% if request.user.is_authenticated and user.role == 'employee' %}
                            {% is_already_applied job request.user as is_applied %}
                            {% if is_applied %}
                                <input type="button" class="btn btn-outline-white-primary" value="Already applied"/>
                            {% else %}
                                <form action="{% url 'jobs:apply-job' job.id %}" method="post">
                                    {% csrf_token %}
                                    <input type="hidden" name="job" value="{{ job.id }}">
                                    <input type="submit" class="btn btn-outline-white-primary"
                                           value="Apply for this job"/>
                                </form>
                            {% endif %}
                        {% endif %}
                    </div>
                </div>
                <div class="col-lg-1"></div>
                <div class="col-lg-3">
                    <h4>About {{ job.company_name }}</h4>
                    <p class="job-detail__company-description">{{ job.company_description | safe }}</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>
                        <a href="#" data-toggle="tooltip" data-placement="top" title="Twitter" class="twitter">
                            <i class="fa fa-twitter"></i>
                        </a>
                        <a href="#" data-toggle="tooltip" data-placement="top" title="Facebook" class="facebook">
                            <i class="fa fa-facebook"></i>
                        </a>
                    </p>
                    {% if user.is_authenticated and user.role == 'employee' %}
                        <div class="job-detail__apply-top">
                            {% if is_applied %}
                                <input type="button" class="btn btn-outline-white-primary" value="Already applied"/>
                            {% else %}
                                <form action="{% url 'jobs:apply-job' job.id %}" method="post">
                                    {% csrf_token %}
                                    <input type="hidden" name="job" value="{{ job.id }}">
                                    <input type="submit" class="btn btn-outline-white-primary"
                                           value="Apply for this job"/>
                                </form>
                            {% endif %}
                        </div>
                    {% endif %}
                </div>
            </div>
        </div>
    </section>

{% endblock %}
