{% extends "base.html" %}
{% load static i18n %}

{% block title %}Create New Job Post - {{ block.super }}{% endblock %}

{% block customCSS %}

<style>
    /* ================================================= */
    /* THEME VARIABLES AND GLOBAL STYLES (Keep existing) */
    /* ================================================= */
    :root {
        --kaauh-teal: #00636e;
        --kaauh-teal-dark: #004a53;
        --kaauh-border: #eaeff3;
        --kaauh-primary-text: #343a40;
    }

    .text-primary { color: var(--kaauh-teal) !important; }
    .btn-main-action, .btn-primary {
        background-color: var(--kaauh-teal);
        border-color: var(--kaauh-teal);
        color: white;
        font-weight: 600;
        padding: 0.6rem 1.2rem;
        transition: all 0.2s ease;
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
    }
    .btn-main-action:hover, .btn-primary:hover {
        background-color: var(--kaauh-teal-dark);
        border-color: var(--kaauh-teal-dark);
        transform: translateY(-1px);
        box-shadow: 0 4px 8px rgba(0,0,0,0.15);
    }
    .btn-secondary {
        background-color: #f8f9fa;
        color: var(--kaauh-teal-dark);
        border: 1px solid var(--kaauh-border);
        font-weight: 500;
    }
    .btn-secondary:hover {
        background-color: #e9ecef;
        color: white;
        border-color: var(--kaauh-teal-dark);
    }
   

    /* Secondary Button Style */
    .btn-outline-secondary {
        color: var(--kaauh-teal-dark);
        border-color: var(--kaauh-teal);
    }
    .btn-outline-secondary:hover {
        background-color: var(--kaauh-teal-dark);
        color: white;
        border-color: var(--kaauh-teal-dark);
    }

    .card {
        border: 1px solid var(--kaauh-border);
        border-radius: 0.75rem;
        overflow: hidden;
        box-shadow: 0 4px 12px rgba(0,0,0,0.06);
        background-color: white;
    }
    .card-header-themed {
        background-color: #f0f8ff;
        border-bottom: 2px solid var(--kaauh-teal);
        color: var(--kaauh-teal-dark);
        font-weight: 700;
        padding: 1rem 1.5rem;
    }
    .form-label {
        font-weight: 600;
        color: var(--kaauh-primary-text);
        margin-bottom: 0.3rem;
        display: block;
    }
    .card-body input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="submit"]):not([type="button"]):not([type="reset"]),
    .card-body select {
        border-radius: 0.5rem;
        border: 1px solid #ced4da;
        width: 100%;
        padding: 0.375rem 0.75rem;
        box-sizing: border-box;
    }

    /* ================================================= */
    /* REMOVED SUMMERNOTE CSS AND ADDED CKEDITOR 5 BASE STYLES */
    /* ================================================= */

    /* CKEditor 5 base styling for the container */
    .ck-editor__editable_inline {
        /* This sets the content area height/min-height */
        min-height: 200px; /* A default height */
        border-radius: 0 0 0.5rem 0.5rem;
        border: 1px solid #ced4da;
    }

    /* Override min-height for specific fields using ID */
    #id_description .ck-editor__editable_inline { min-height: 300px; }
    #id_qualifications .ck-editor__editable_inline { min-height: 200px; }
    #id_benefits .ck-editor__editable_inline,
    #id_application_instructions .ck-editor__editable_inline { min-height: 150px; }

    .ck-toolbar {
        border-radius: 0.5rem 0.5rem 0 0 !important;
    }
</style>
{{form.media.css}}
{% endblock %}

{% block content %}
<div class="container-fluid py-4">
    <h1 class="h3 mb-4 text-primary fw-bold">
        <i class="fas fa-bullhorn me-2"></i> {% if form.instance.pk %} {% trans "Edit Job Posting" %} {% else %} {% trans "Create New Job Posting" %} {% endif %}
    </h1>

    <form method="post" id="jobForm" class="mb-5" enctype="multipart/form-data">
        {% csrf_token %}

        {# ================================================= #}
        {# SECTION 1: CORE POSITION DETAILS #}
        {# ================================================= #}
        <div class="card mb-4 shadow-sm">
            <div class="card-header-themed">
                <h5><i class="fas fa-info-circle"></i> {% trans "Core Position Details" %}</h5>
            </div>
            <div class="card-body">
                <div class="row g-4">
                    <div class="col-md-12">
                        <div>
                            <label for="{{ form.title.id_for_label }}" class="form-label">{% trans "Job Title" %} <span class="text-danger">*</span></label>
                            {{ form.title }}
                            {% if form.title.errors %}<div class="text-danger small mt-1">{{ form.title.errors }}</div>{% endif %}
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div>
                            <label for="{{ form.job_type.id_for_label }}" class="form-label">{% trans "Job Type" %} <span class="text-danger">*</span></label>
                            {{ form.job_type }}
                            {% if form.job_type.errors %}<div class="text-danger small mt-1">{{ form.job_type.errors }}</div>{% endif %}
                        </div>
                    </div>
                    
                    <div class="col-md-6">
                        <div>
                            <label for="{{ form.workplace_type.id_for_label }}" class="form-label">{% trans "Workplace Type" %} <span class="text-danger">*</span></label>
                            {{ form.workplace_type }}
                            {% if form.workplace_type.errors %}<div class="text-danger small mt-1">{{ form.workplace_type.errors }}</div>{% endif %}
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div>
                            <label for="{{ form.application_deadline.id_for_label }}" class="form-label">{% trans "Application Deadline" %}<span class="text-danger">*</span></label>
                            {{ form.application_deadline }}
                            {% if form.application_deadline.errors %}<div class="text-danger small mt-1">{{ form.application_deadline.errors }}</div>{% endif %}
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div>
                            <label for="{{ form.department.id_for_label }}" class="form-label">{% trans "Department" %}</label>
                            {{ form.department }}
                            {% if form.department.errors %}<div class="text-danger small mt-1">{{ form.department.errors }}</div>{% endif %}
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div>
                            <label for="{{ form.open_positions.id_for_label }}" class="form-label">{% trans "Open Positions" %}</label>
                            {{ form.open_positions }}
                            {% if form.open_positions.errors %}<div class="text-danger small mt-1">{{ form.open_positions.errors }}</div>{% endif %}
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div>
                            <label for="{{ form.max_applications.id_for_label }}" class="form-label">{% trans "Max Applications" %}</label>
                            {{ form.max_applications }}
                            {% if form.max_applications.errors %}<div class="text-danger small mt-1">{{ form.max_applications.errors }}</div>{% endif %}
                        </div>
                    </div>
                </div>
            </div>
        </div>


        

        
        {# ================================================= #}
        {# SECTION 4: JOB CONTENT (CKEDITOR 5 Fields) #}
        {# ================================================= #}
        <div class="card mb-4 shadow-sm">
            <div class="card-header-themed">
                <h5><i class="fas fa-file-alt"></i> {% trans "Job Content" %}</h5>
            </div>
            <div class="card-body">
                <div class="row g-4">
                    <div class="col-12">
                        <div>
                            <label for="{{ form.description.id_for_label }}" class="form-label">{% trans "Job Description" %} <span class="text-danger">*</span></label>
                            {{ form.description}}
                            {% if form.description.errors %}<div class="text-danger small mt-1">{{ form.description.errors }}</div>{% endif %}
                        </div>
                    </div>

                    <div class="col-12">
                        <div>
                            <label for="{{ form.qualifications.id_for_label }}" class="form-label">{% trans "Qualifications and Requirements" %}</label>
                            {{ form.qualifications}}
                            {% if form.qualifications.errors %}<div class="text-danger small mt-1">{{ form.qualifications.errors }}</div>{% endif %}
                        </div>
                    </div>
                </div>
            </div>
        </div>

        {# ================================================= #}
        {# SECTION 5:  APPLICATION Instructions #}
        {# ================================================= #}
        <div class="card mb-4 shadow-sm">
            <div class="card-header-themed">
                <h5><i class="fas fa-dollar-sign"></i> {% trans "Benefits & Application Instructions" %}</h5>
            </div>
            <div class="card-body">
                <div class="row g-4">

                    {% comment %} (application_url comment removed for brevity) {% endcomment %}

                    <div class="col-12">
                        <div>
                            <label for="{{ form.benefits.id_for_label }}" class="form-label">{% trans "Benefits" %}</label>
                            {{ form.benefits }}
                            {% if form.benefits.errors %}<div class="text-danger small mt-1">{{ form.benefits.errors }}</div>{% endif %}
                        </div>
                    </div>

                    <div class="col-12">
                        <div>
                            <label for="{{ form.application_instructions.id_for_label }}" class="form-label">{% trans "Application Instructions" %}</label>
                            {{ form.application_instructions }}
                            {% if form.application_instructions.errors %}<div class="text-danger small mt-1">{{ form.application_instructions.errors }}</div>{% endif %}
                        </div>
                    </div>
                </div>
            </div>
        </div>
        {# ================================================= #}
        {# SECTION 2: INTERNAL AND PROMOTION #}
        {# ================================================= #}

        <div class="card mb-4 shadow-sm">
            <div class="card-header-themed">
                <h5><i class="fas fa-tags"></i> {% trans "Internal & Promotion" %}</h5>
            </div>
            <div class="card-body">
                <div class="row g-4">
                    <div class="col-md-6">
                        <div>
                            <label for="{{ form.position_number.id_for_label }}" class="form-label">{% trans "Position Number" %}</label>
                            {{ form.position_number }}
                            {% if form.position_number.errors %}<div class="text-danger small mt-1">{{ form.position_number.errors }}</div>{% endif %}
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div>
                            <label for="{{ form.reporting_to.id_for_label }}" class="form-label">{% trans "Reports To" %}</label>
                            {{ form.reporting_to }}
                            {% if form.reporting_to.errors %}<div class="text-danger small mt-1">{{ form.reporting_to.errors }}</div>{% endif %}
                        </div>
                    </div>
                    


                    <div class="col-12">
                        <div>
                            <label for="{{ form.hash_tags.id_for_label }}" class="form-label">{% trans "Hashtags (For Promotion/Search on Linkedin)" %}</label>
                            {{ form.hash_tags }}
                            {% if form.hash_tags.errors %}<div class="text-danger small mt-1">{{ form.hash_tags.errors }}</div>{% endif %}
                            <div class="form-text">{% trans "Comma-separated list of hashtags, e.g., #hiring, #professor" %}</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        {# ================================================= #}
        {# SECTION 3: LOCATION AND Salary #}
        {# ================================================= #}

        <div class="card mb-4 shadow-sm">
            <div class="card-header-themed">
                <h5><i class="fas fa-map-marker-alt"></i> {% trans "Location & Salary" %}</h5>
            </div>
            <div class="card-body">
                <div class="row g-4">
                    <div class="col-md-4">
                        <div>
                            <label for="{{ form.location_city.id_for_label }}" class="form-label">{% trans "City" %}</label>
                            {{ form.location_city }}
                            {% if form.location_city.errors %}<div class="text-danger small mt-1">{{ form.location_city.errors }}</div>{% endif %}
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div>
                            <label for="{{ form.location_state.id_for_label }}" class="form-label">{% trans "State/Province" %}</label>
                            {{ form.location_state }}
                            {% if form.location_state.errors %}<div class="text-danger small mt-1">{{ form.location_state.errors }}</div>{% endif %}
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div>
                            <label for="{{ form.location_country.id_for_label }}" class="form-label">{% trans "Country" %}</label>
                            {{ form.location_country }}
                            {% if form.location_country.errors %}<div class="text-danger small mt-1">{{ form.location_country.errors }}</div>{% endif %}
                        </div>
                    </div>

                    

                    <div class="col-md-12">
                        <div>
                            <label for="{{ form.salary_range.id_for_label }}" class="form-label">{% trans "Salary Range" %}</label>
                            {{ form.salary_range }}
                            {% if form.salary_range.errors %}<div class="text-danger small mt-1">{{ form.salary_range.errors }}</div>{% endif %}
                        </div>
                    </div>

                </div>
            </div>
        </div>

        {# ================================================= #}
        {# ACTION BUTTONS #}
        {# ================================================= #}
        <div class="d-flex justify-content-between pt-2">
            <a href="{% url 'job_list' %}" class="btn btn-outline-secondary">
                <i class="fas fa-arrow-left me-1"></i> {% trans "Cancel" %}
            </a>
            <button type="submit" class="btn btn-main-action">
                <i class="fas fa-save me-1"></i> {% trans "Save Job" %}
            </button>
        </div>
    </form>
</div>



{% endblock %}

{% block customJS %}

{{ form.media.js }}
{% endblock%}