$(document).ready(function() {
    let selctor = $('#supporttxt');
    let placeholder = 'Please write what is your problem or needs';
    common_helper.init_summernote(selctor,placeholder);
})
const closeTicket = (userData,url) => {
    let html_content = `<h4>Are you sure you want to close the ticket?</h4>`;
    const swalresponse = common_helper.swalAleart(html_content, 'warning', 450, true, '', true, true, 'Yes');
    swalresponse.then(async function (result) {
        let data = {
            action: 'CLOSE_SUPPORT_TICKET',
            userData: userData,
            _token: $('meta[name="csrf-token"]').attr('content')
        };
        if (result.isConfirmed) {
            await common_helper.globalAjaxRequestAsync(url, 'POST', data ,closeTicketCallBack);
        }
    });
}
const closeTicketCallBack = (response)=>{
    if (response.status) {
        Swal.fire({icon: response.type, title: response.message, width: 450,closeOnConfirm: true});
        window.location = $('[name="redirect_url"]').val();
    } else {
        Swal.fire({icon: response.type, title: response.message, width: 450,closeOnConfirm: true});
    }

}

const reminder_btn_click = (userData,url) => {
    let html_content = `<h4>Are you sure you want to send reminder for the ticket?</h4>`;
    const swalresponse = common_helper.swalAleart(html_content, 'warning', 450, true, '', true, true, 'Yes');
    swalresponse.then(async function (result) {
        let data = {
            action: 'REMINDER_SUPPORT_TICKET',
            supportId: userData,
            _token: $('meta[name="csrf-token"]').attr('content')
        };
        if (result.isConfirmed) {
            await common_helper.globalAjaxRequestAsync(url, 'POST', data ,reminderCallBack);
        }
    });
}

const reminderCallBack = (response)=>{
    if (response.status) {
        Swal.fire({icon: response.type, title: response.message, width: 450,closeOnConfirm: true});
    } else {
        Swal.fire({icon: response.type, title: response.message, width: 450,closeOnConfirm: true});
    }

}
