{% extends "base.html" %}

{% block title %}{{ job.title }} - University ATS{% endblock %}

{% block content %}
<div class="row">
    <div class="col-lg-8">
        <div class="card">
            <div class="card-header d-flex justify-content-between align-items-center">
                <h2>{{ job.title }}</h2>
                <span class="badge bg-{{ job.status|lower }} status-badge">
                    {{ job.get_status_display }}
                </span>
            </div>
            <div class="card-body">
                <!-- Job Details -->
                <div class="row mb-3">
                    <div class="col-md-6">
                        <strong>Department:</strong> {{ job.department|default:"Not specified" }}
                    </div>
                    <div class="col-md-6">
                        <strong>Position Number:</strong> {{ job.position_number|default:"Not specified" }}
                    </div>
                </div>
                
                <div class="row mb-3">
                    <div class="col-md-6">
                        <strong>Job Type:</strong> {{ job.get_job_type_display }}
                    </div>
                    <div class="col-md-6">
                        <strong>Workplace:</strong> {{ job.get_workplace_type_display }}
                    </div>
                </div>
                
                <div class="row mb-3">
                    <div class="col-md-6">
                        <strong>Location:</strong> {{ job.get_location_display }}
                    </div>
                    <div class="col-md-6">
                        <strong>Created By:</strong> {{ job.created_by|default:"Not specified" }}
                    </div>
                </div>
                
                {% if job.salary_range %}
                <div class="row mb-3">
                    <div class="col-12">
                        <strong>Salary Range:</strong> {{ job.salary_range }}
                    </div>
                </div>
                {% endif %}
                
                {% if job.start_date %}
                <div class="row mb-3">
                    <div class="col-12">
                        <strong>Start Date:</strong> {{ job.start_date }}
                    </div>
                </div>
                {% endif %}
                
                {% if job.application_deadline %}
                <div class="row mb-3">
                    <div class="col-12">
                        <strong>Application Deadline:</strong> {{ job.application_deadline }}
                        {% if job.is_expired %}
                            <span class="badge bg-danger">EXPIRED</span>
                        {% endif %}
                    </div>
                </div>
                {% endif %}

                
                <!-- Description -->
                {% if job.description %}
                <div class="mb-3">
                    <h5>Description</h5>
                    <div>{{ job.description|linebreaks }}</div>
                </div>
                {% endif %}
                
                {% if job.qualifications %}
                <div class="mb-3">
                    <h5>Qualifications</h5>
                    <div>{{ job.qualifications|linebreaks }}</div>
                </div>
                {% endif %}
                
                {% if job.benefits %}
                <div class="mb-3">
                    <h5>Benefits</h5>
                    <div>{{ job.benefits|linebreaks }}</div>
                </div>
                {% endif %}
                
                {% if job.application_instructions %}
                <div class="mb-3">
                    <h5>Application Instructions</h5>
                    <div>{{ job.application_instructions|linebreaks }}</div>
                </div>
                {% endif %}
                
                <!-- Application URL -->
                {% if job.application_url %}
                <div class="mb-3">
                    <button type="button" class="btn btn-info" data-bs-toggle="modal" data-bs-target="#myModalForm">
                       Upload Image for Post
                      </button>
                </div>
                {% endif %}
            </div>
        </div>
    </div>
    
    <div class="col-lg-4">
        <!-- LinkedIn Integration Card -->
        <div class="card mb-4">
            <div class="card-header">
                <h5><i class="fab fa-linkedin"></i> LinkedIn Integration</h5>
            </div>
            <div class="card-body">
                {% if job.posted_to_linkedin %}
                    <div class="alert alert-success">
                        <i class="fas fa-check-circle"></i> Posted to LinkedIn successfully!
                    </div>
                    {% if job.linkedin_post_url %}
                        <a href="{{ job.linkedin_post_url }}" target="_blank" class="btn btn-primary w-100 mb-2">
                            <i class="fab fa-linkedin"></i> View on LinkedIn
                        </a>
                    {% endif %}
                    <small class="text-muted">Posted on: {{ job.linkedin_posted_at|date:"M d, Y" }}</small>
                {% else %}
                    <p class="text-muted">This job has not been posted to LinkedIn yet.</p>
                {% endif %}
                
                <form method="post" action="{% url 'jobs:post_to_linkedin' job.pk %}" class="mt-3">
                    {% csrf_token %}
                    <button type="submit" class="btn btn-primary w-100" 
                            {% if not request.session.linkedin_authenticated %}disabled{% endif %}>
                        <i class="fab fa-linkedin"></i> 
                        {% if job.posted_to_linkedin %}Re-post to LinkedIn{% else %}Post to LinkedIn{% endif %}
                    </button>
                </form>
                
                {% if not request.session.linkedin_authenticated %}
                    <small class="text-muted">You need to <a href="{% url 'jobs:linkedin_login' %}">authenticate with LinkedIn</a> first.</small>
                {% endif %}
                
                {% if job.linkedin_post_status and 'ERROR' in job.linkedin_post_status %}
                    <div class="alert alert-danger mt-2">
                        <small>{{ job.linkedin_post_status }}</small>
                    </div>
                {% endif %}
            </div>
        </div>
        <div class="card border-secondary shadow-sm mb-4">
            <div class="card-header bg-secondary text-white">
                <h5 class="mb-0">Applicant Form Management</h5>
            </div>
            <div class="card-body d-grid gap-2">
                
                <p class="text-muted mb-3">
                    Manage the custom application forms associated with this job posting.
                </p>

                {# Primary Action: Highlight the creation of a NEW form #}
                <a href="{% url 'applicant:create_form' job_id=job.internal_job_id %}" 
                class="btn btn-lg btn-success">
                    <i class="fas fa-plus-circle me-2"></i> Create New Form
                </a>
                
                {# Secondary Action: Make the list button less prominent #}
                <a href="{% url 'applicant:job_forms_list' job.internal_job_id %}" 
                class="btn btn-sm btn-outline-primary">
                    View All Existing Forms
                </a>
                
            </div>
        </div>
        
        <!-- Internal Info Card -->
        <div class="card">
            <div class="card-header">
                <h5>Internal Information</h5>
            </div>
            <div class="card-body">
                <p><strong>Internal Job ID:</strong> {{ job.internal_job_id }}</p>
                <p><strong>Created:</strong> {{ job.created_at|date:"M d, Y" }}</p>
                <p><strong>Last Updated:</strong> {{ job.updated_at|date:"M d, Y" }}</p>
                {% if job.reporting_to %}
                    <p><strong>Reports To:</strong> {{ job.reporting_to }}</p>
                {% endif %}
            </div>
        </div>
    </div>
</div>

<div class="mt-3 mb-5">
    <a href="{% url 'jobs:edit_job' job.pk %}" class="btn btn-outline-primary me-2">
        <i class="fas fa-edit"></i> Edit Job
    </a>
    <a href="{% url 'jobs:job_list' %}" class="btn btn-outline-secondary">
        <i class="fas fa-arrow-left"></i> Back to Jobs
    </a>
</div>

<!--modal class for upload file-->
{% include "jobs/partials/image_upload.html" %}
{% endblock %}