<!-- form  non field errors  -->
{% load i18n %}
{% load static %}
{% load widget_tweaks %}

{% if feedback_form.errors %}
<div class="oh-wrapper">
    <div class="oh-alert-container">
        {% for error in feedback_form.non_field_errors %}
        <div class="oh-alert oh-alert--animated oh-alert--danger">{{ error }}</div>
        {% endfor %}
    </div>
</div>
{% endif %}
<form hx-post="{%url 'feedback-update' id=feedback_form.instance.id %}" hx-target="#feedbackModalTarget" class="oh-profile-section">
    {{feedback_form.non_field_errors}}
   {% csrf_token %}
        <div class="oh-input__group ">
            <label class="oh-input__label" for="{{feedback_form.review_cycle.id_for_label}}">{% trans "Review Cycle" %}</label>
            {{feedback_form.review_cycle}}
            {{feedback_form.review_cycle.errors}}
        </div>
        <div class="row">
            <div class="col-12 col-sm-12 col-md-6 col-lg-6">
                <div class="oh-input__group">
                    <div class="oh-input__group">
                        <label class="oh-input__label" for="{{feedback_form.employee_id.id_for_label}}">{% trans "Employee" %}</label>
                        {{feedback_form.employee_id }}
                        {{feedback_form.employee_id.errors }}
                    </div>
                </div>
            </div>
            <div class="col-12 col-sm-12 col-md-6 col-lg-6">
                <div class="oh-input__group">
                    <div class="oh-input__group">
                        <label class="oh-input__label" for="{{feedback_form.manager_id.id_for_label}}">{% trans "Manager" %}</label>
                        {{feedback_form.manager_id}}
                        {{feedback_form.manager_id.errros}}
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-12 col-sm-12 col-md-6 col-lg-6">
                <div class="oh-input__group">
                    <div class="oh-input__group">
                        <label class="oh-input__label" for="{{feedback_form.subordinate_id.id_for_label}}">{% trans "Subordinates" %}</label>
                        {{feedback_form.subordinate_id}}
                        {{feedback_form.subordinate_id.errors}}
                    </div>
                </div>
            </div>
            <div class="col-12 col-sm-12 col-md-6 col-lg-6">
                <div class="oh-input__group">
                    <div class="oh-input__group">
                        <label class="oh-input__label" for="{{feedback_form.colleague_id.id_for_label}}">{% trans "Colleague" %}</label>
                        {{feedback_form.colleague_id}}
                        {{feedback_form.colleague_id.errors}}
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-12 col-sm-12 col-md-6 col-lg-6">
                <div class="oh-input__group">
                    <div class="oh-input__group">
                        <label class="oh-input__label" for="{{feedback_form.start_date.id_for_label}}">{% trans "Start Date" %}</label>
                        {{feedback_form.start_date}}
                        {{feedback_form.start_date.errors}}
                    </div>
                </div>
            </div>
            <div class="col-12 col-sm-12 col-md-6 col-lg-6">
                <div class="oh-input__group">
                    <div class="oh-input__group">
                        <label class="oh-input__label" for="{{feedback_form.end_date.id_for_label}}">{% trans "End Date" %}</label>
                        {{feedback_form.end_date}}
                        {{feedback_form.end_date.errors}}
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-12 col-sm-12 col-md-6 col-lg-6">
                <div class="oh-input__group">
                    <label class="oh-input__label" for="{{feedback_form.question_template_id.id_for_label}}">{% trans "Question Template" %}</label>
                    {{feedback_form.question_template_id}}
                    {{feedback_form.question_template_id.errors}}
                </div>
            </div>
            <div class="col-12 col-sm-12 col-md-6 col-lg-6">
                <div class="oh-input__group">
                    <label class="oh-input__label" for="{{id_employee_key_results_id}}">{% trans "Key Result" %}</label>
                    <select name="employee_key_results_id" id="id_employee_key_results_id"
                        class="oh-select  oh-select--lg oh-select-no-search w-100 oh-select-2--large"
                        multiple="multiple" style="display: none;">
                        <option value="">------------------</option>
                    </select>
                </div>
            </div>

        </div>
        <div class="row">
            <div class="col-12 col-sm-12 col-md-6 col-lg-6 mb-5" id="">
                <div class="oh-input__group">
                    <label class="oh-input__label" for="{{feedback_form.cyclic_feedback.id_for_label}}">{% trans "Is Cyclic Feedback" %}</label>
                    <div class="oh-switch">
                    {{feedback_form.cyclic_feedback}}
                    </div>
                    {{feedback_form.cyclic_feedback.errors}}
                </div>
            </div>
            <div class="col-12 col-sm-12 col-md-6 col-lg-6" style="display:none" id="cyclic_feedback_period">
                <div class="oh-input__group">
                    <label class="oh-input__label" for="id_employee_key_results_id">{% trans "Cycle Period" %}</label>
                    <div class="w-100 d-flex">
                        {{feedback_form.cyclic_feedback_days_count}}
                        {{feedback_form.cyclic_feedback_period}}
                    </div>
                </div>
            </div>
        </div>
        <div class="w-100 d-flex align-items-center justify-content-end">
            <button
                type="submit"
                class="oh-btn oh-btn--secondary oh-btn--w-100-resp"
            >
                {% trans "Save" %}
            </button>
        </div>
    </form>

<button id="colleguesButton" hx-get="{% url 'get-collegues' %}" hx-target="#id_colleague_id" hidden > </button>
<button id="managerButton" hx-get="{% url 'get-collegues' %}" hx-target="#id_manager_id" hidden > </button>
<button id="subordinatesButton" hx-get="{% url 'get-collegues' %}" hx-target="#id_subordinate_id" hidden > </button>
<button id="keyresultButtton" hx-get="{% url 'get-collegues' %}" hx-target="#id_employee_key_results_id" hidden > </button>

<script>
    $(document).ready(function() {
        if ($("#id_cyclic_feedback").prop("checked")){
            $("#cyclic_feedback_period").show()
        }
        $("#id_cyclic_feedback").on("change", function(){
            if (this.checked){
            $("#cyclic_feedback_period").show()
            }
            else{
            $("#cyclic_feedback_period").hide()
            }
        })
    })
</script>

<script src="{% static 'src/feedback/feedback_creation.js' %}"></script>
