{% extends "./template.html" %}
{% block content %}
{% load static %}

<form action={% url 'email' location_id destination %} method="post" enctype="multipart/form-data" class="email" multiple="multiple" data-is-stacked="0">
{% csrf_token %}
    <div class="card mt-4">
        <div class="card-header">
            <h2>Email</h2>
        </div>
        <div class="card-body">
            {% csrf_token %}
            {{ email_form.media }}
            <div class="form-row">
                {{ email_form.organisation_email  }}
                {% if destination == "organisation" %}
                    <a id="remove_organisation_id" href="javascript:void(0)" onclick="remove_organisation()">Click here to remove organisation from email list</a>
                {% endif %}
            </div>
            <div class="form-row">
                <label for="id_to_email" class="col-md-1">To: </label>
                {{ email_form.to_email }}
            </div>
            <div class="form-row">
                <label for="id_cc_email" class="col-md-1">CC: </label>
                {{ email_form.cc_email }}
            </div>
            <div class="form-row">
                <label for="id_bcc_email" class="col-md-1">BCC: </label>
                {{ email_form.bcc_email }}
            </div>
            <div class="form-row">
                <label for="id_email_subject" class="col-md-1">Subject</label>
                {{ email_form.email_subject }}
            </div>
            <div class="form-group">
                {{ email_form.email_content }}
            </div>
            <div class="form-text">
                <label for="id_is_private">Private Email: </label>
                {{ email_form.is_private }}
            </div>
            {% if destination == 'quote' %}
                <div class="form-row">
                    <div class="form-group">
                        <label for="id_email_quote">Send Quote: </label>
                        {{ email_form.email_quote }}
                    </div>
                    <div class="form-group">
                        <label for="id_quote_template_description">Quote Template: </label>
                        {{ email_form.quote_template_description }}
                    </div>
                </div>
            {% endif %}
            <div class="form-row">
                <input type="submit" value="Send Email" class="btn btn-primary form-control col-md-6">
                {% if destination == "customer" %}
                    <a href="{% url 'customer_information' location_id %}" class="btn btn-warning form-control col-md-6">Cancel Email</a>
                {% elif destination == 'organisation' %}
                    <a href="{% url 'organisation_information' location_id %}" class="btn btn-warning form-control col-md-6">Cancel Email</a>
                {% elif destination == 'task' %}
                    <a href="{% url 'task_information' location_id %}" class="btn btn-warning form-control col-md-6">Cancel Email</a>
                {% elif destination == 'quote' %}
                    <a href="{% url 'quote_information' location_id %}" class="btn btn-warning form-control col-md-6">Cancel Email</a>
                {% elif destination == 'project' %}
                    <a href="{% url 'project_information' location_id %}" class="btn btn-warning form-control col-md-6">Cancel Email</a>
                {% else %}
                    <a href="{% url 'dashboard' %}" class="btn btn-warning form-control col-md-6">Cancel Email</a>
                {% endif %}
            </div>
        </div>
    </div>
</form>
<script>
    function remove_organisation() {
        $("#id_organisation_email").val("");
        $("#remove_organisation_id").html("");
        $("#id_to_email").prop('required',true);
    }
</script>
{% endblock %}