function createTicketShow () {
    $.ajax({
        headers: { "X-CSRFToken": $('input[name=csrfmiddlewaretoken]').val() },
        url: '/ru/messages/support_create_ticket_form/',
        type: "POST",
        // async: true,
        cache: false,
        processData: false,
        contentType: false,
        // enctype: 'json',
        // data: formData,
        success: function(data){

            document.querySelector(".insert-tech-place").innerHTML = data.html;

        },
    });
}

function countLetters () {
    let area = document.querySelector(".el-form-create-ticket-textarea")
    let count = area.value.length
    if (count <= 500) {
        let ins_area = document.querySelector(".letrs-count-span")
        ins_area.innerHTML = count
    }
    else {
        area.setAttribute("disabled","disabled")
    }
}

// var input;


function inputQuest (){
    event.preventDefault()
    // let input = document.querySelector(".create-ticket-file")
    let input = document.createElement("input");
    input.setAttribute("type", "file")
    input.style.display = "none"
    input.click()
    // console.log("asd")

    return input
}


function attachFileCreateTicket () {
    let input = inputQuest()
    let file = input.files[0]
    // let file_url = URL.createObjectURL(file)



    let data = file
    $.ajax({
        headers: { "X-CSRFToken": $('input[name=csrfmiddlewaretoken]').val() },
        url: '/ru/user_account/support_tickets/',
        type: "POST",
        // async: true,
        cache: false,
        processData: false,
        contentType: false,
        // enctype: 'json',
        data: data,
        success: function(data){

            document.querySelector(".insert-tech-place").innerHTML = data.html;

        },
    });

}

function attachFilemeassge () {
    let input = inputQuest()
    let file = input.files[0]
    // let file_url = URL.createObjectURL(file)



    let data = file
    $.ajax({
        headers: { "X-CSRFToken": $('input[name=csrfmiddlewaretoken]').val() },
        url: '/ru/user_account/support_tickets/',
        type: "POST",
        // async: true,
        cache: false,
        processData: false,
        contentType: false,
        // enctype: 'json',
        data: data,
        success: function(data){

            document.querySelector(".insert-tech-place").innerHTML = data.html;

        },
    });
    input.remove()
}

function createTicket (el) {
    event.preventDefault()
    let form = el.form
    var formData = new FormData(form);
    $.ajax({
        headers: { "X-CSRFToken": $('input[name=csrfmiddlewaretoken]').val() },
        url: '/ru/messages/create_ticket/',
        type: "POST",
        // async: true,
        cache: false,
        processData: false,
        contentType: false,
        // enctype: 'json',
        data: formData,
        success: function(data){

            document.querySelector(".insert-tech-place").innerHTML = data.html;

        },
        error: function (data){

            document.querySelector(".insert-tech-place").innerHTML = data.responseJSON.html;

        }
    });
}
