var selectors={formId:"#tablesome-importing-data-form",submit:"#tablesome-importing-data-form .tablesome__button--submit",readFirstRowAsColumn:"#read_first_row_as_column",tableTitle:"#table_title"},page={init:function(){this.eventListeners()},eventListeners:function(){jQuery(selectors.submit).on("click",(function(e){e.preventDefault();var t=page.getValidatedFormValues();if(!1===t)return!1;var a=page.getFormData(t);page.formSubmission(a)}))},disableSubmitButton:function(){jQuery(selectors.submit).attr("disabled","disabled")},enableSubmitButton:function(){jQuery(selectors.submit).removeAttr("disabled")},validateImportForm:function(){return page.formValidations()},getValidatedFormValues:function(){var e=document.getElementById("file_attachment"),t=e?e.files[0]:[];if(void 0===t)return alert("Please attach the file"),!1;var a=t.name.split(".").pop().toLowerCase();if(-1==["xlsx","csv"].indexOf(a))return alert("Only Supports with xlsx and csv file formats"),!1;var r=!1;return jQuery(selectors.formId).find(selectors.readFirstRowAsColumn).is(":checked")&&(r=!0),{file:t,title:jQuery(selectors.formId).find(selectors.tableTitle).val(),readFirstRowAsColumn:r}},getFormData:function(e){var t=new FormData;return t.append("file_attachment",e.file),t.append("action","importing_data"),t.append("nonce",tablesome_ajax_object.nonce),t.append("read_first_row_as_column",e.readFirstRowAsColumn),t.append("table_title",e.title),t},formSubmission:function(e){page.disableSubmitButton(),jQuery.ajax({type:"post",url:tablesome_ajax_object.ajax_url,cache:!1,data:e,processData:!1,contentType:!1,success:function(e){if(page.enableSubmitButton(),"failed"==e.status)return alert(e.message),!1;alert(e.message),window.location.replace(e.edit_page_url)}})}};module.exports=page;