!function(){"use strict";function e(){this.filterResults={},this.filterLimit=20}e.prototype.bindEventHandlers=function(){var s=this;$("#customers").on("submit","#filter-customers form",function(e){e.preventDefault();var t=$("#filter-customers .key").val();$("#filter-customers .selected").removeClass("selected"),s.filterLimit=20,s.resetForm(),s.filter(t)}),$("#customers").on("click","#filter-customers .clear",function(){$("#filter-customers .key").val(""),s.filterLimit=20,s.filter(""),s.resetForm()}),$("#customers").on("click",".customer-row",function(){var t,e;$("#filter-customers .filter").prop("disabled")||(t=$(this).attr("data-id"),e=s.filterResults.find(function(e){return Number(e.id)===Number(t)}),s.display(e),$("#filter-customers .selected").removeClass("selected"),$(this).addClass("selected"),$("#edit-customer, #delete-customer").prop("disabled",!1))}),$("#customers").on("click","#add-customer",function(){s.resetForm(),$("#add-edit-delete-group").hide(),$("#save-cancel-group").show(),$(".record-details").find("input, select, textarea").prop("disabled",!1),$("#filter-customers button").prop("disabled",!0),$("#filter-customers .results").css("color","#AAA")}),$("#customers").on("click","#edit-customer",function(){$(".record-details").find("input, select, textarea").prop("disabled",!1),$("#add-edit-delete-group").hide(),$("#save-cancel-group").show(),$("#filter-customers button").prop("disabled",!0),$("#filter-customers .results").css("color","#AAA")}),$("#customers").on("click","#cancel-customer",function(){var e=$("#customer-id").val();s.resetForm(),e&&s.select(e,!0)}),$("#customers").on("click","#save-customer",function(){var e={first_name:$("#first-name").val(),last_name:$("#last-name").val(),email:$("#email").val(),phone_number:$("#phone-number").val(),address:$("#address").val(),city:$("#city").val(),zip_code:$("#zip-code").val(),notes:$("#notes").val(),timezone:$("#timezone").val(),language:$("#language").val()||"english"};$("#customer-id").val()&&(e.id=$("#customer-id").val()),s.validate()&&s.save(e)}),$("#customers").on("click","#delete-customer",function(){var e=$("#customer-id").val(),t=[{text:EALang.cancel,click:function(){$("#message-box").dialog("close")}},{text:EALang.delete,click:function(){s.delete(e),$("#message-box").dialog("close")}}];GeneralFunctions.displayMessageBox(EALang.delete_customer,EALang.delete_record_prompt,t)})},e.prototype.save=function(e){var t=GlobalVariables.baseUrl+"/index.php/backend_api/ajax_save_customer",s={csrfToken:GlobalVariables.csrfToken,customer:JSON.stringify(e)};$.post(t,s).done(function(e){Backend.displayNotification(EALang.customer_saved),this.resetForm(),$("#filter-customers .key").val(""),this.filter("",e.id,!0)}.bind(this))},e.prototype.delete=function(e){var t=GlobalVariables.baseUrl+"/index.php/backend_api/ajax_delete_customer",s={csrfToken:GlobalVariables.csrfToken,customer_id:e};$.post(t,s).done(function(){Backend.displayNotification(EALang.customer_deleted),this.resetForm(),this.filter($("#filter-customers .key").val())}.bind(this))},e.prototype.validate=function(){$("#form-message").removeClass("alert-danger").hide(),$(".has-error").removeClass("has-error");try{var s=!1;if($(".required").each(function(e,t){""===$(t).val()&&($(t).closest(".form-group").addClass("has-error"),s=!0)}),s)throw new Error(EALang.fields_are_required);if(!GeneralFunctions.validateEmail($("#email").val()))throw $("#email").closest(".form-group").addClass("has-error"),new Error(EALang.invalid_email);return!0}catch(e){return $("#form-message").addClass("alert-danger").text(e.message).show(),!1}},e.prototype.resetForm=function(){$(".record-details").find("input, select, textarea").val("").prop("disabled",!0),$(".record-details #timezone").val("UTC"),$("#language").val("english"),$("#customer-appointments").empty(),$("#edit-customer, #delete-customer").prop("disabled",!0),$("#add-edit-delete-group").show(),$("#save-cancel-group").hide(),$(".record-details .has-error").removeClass("has-error"),$(".record-details #form-message").hide(),$("#filter-customers button").prop("disabled",!1),$("#filter-customers .selected").removeClass("selected"),$("#filter-customers .results").css("color","")},e.prototype.display=function(e){$("#customer-id").val(e.id),$("#first-name").val(e.first_name),$("#last-name").val(e.last_name),$("#email").val(e.email),$("#phone-number").val(e.phone_number),$("#address").val(e.address),$("#city").val(e.city),$("#zip-code").val(e.zip_code),$("#notes").val(e.notes),$("#timezone").val(e.timezone),$("#language").val(e.language||"english"),$("#customer-appointments").empty(),e.appointments.length||$("
",{text:EALang.no_records_found}).appendTo("#customer-appointments"),e.appointments.forEach(function(e){var t,s;GlobalVariables.user.role_slug===Backend.DB_SLUG_PROVIDER&&parseInt(e.id_users_provider)!==GlobalVariables.user.id||GlobalVariables.user.role_slug===Backend.DB_SLUG_SECRETARY&&-1===GlobalVariables.secretaryProviders.indexOf(e.id_users_provider)||(t=GeneralFunctions.formatDate(Date.parse(e.start_datetime),GlobalVariables.dateFormat,!0),s=GeneralFunctions.formatDate(Date.parse(e.end_datetime),GlobalVariables.dateFormat,!0),$("",{class:"appointment-row","data-id":e.id,html:[$("",{href:GlobalVariables.baseUrl+"/index.php/backend/index/"+e.hash,html:[$("",{class:"fas fa-edit mr-1"}),$("",{text:e.service.name+" - "+e.provider.first_name+" "+e.provider.last_name}),$("