window.BackendCalendarAppointmentsModal=window.BackendCalendarAppointmentsModal||{},function(e){"use strict";function a(){$("#manage-appointment #save-appointment").on("click",function(){var a,e,t,n,i;!function(){var a=$("#manage-appointment");a.find(".has-error").removeClass("has-error"),a.find(".modal-message").addClass("d-none");try{var t=!1;if(a.find(".required").each(function(e,a){""!==$(a).val()&&null!==$(a).val()||($(a).closest(".form-group").addClass("has-error"),t=!0)}),t)throw new Error(EALang.fields_are_required);if(!GeneralFunctions.validateEmail(a.find("#email").val()))throw a.find("#email").closest(".form-group").addClass("has-error"),new Error(EALang.invalid_email);var e=$("#start-datetime").datetimepicker("getDate");if($("#end-datetime").datetimepicker("getDate")",{"data-id":e.id,text:e.first_name+" "+e.last_name}).appendTo(a)}))}),$("#manage-appointment").on("click","#existing-customers-list div",function(){var a=$(this).attr("data-id"),e=GlobalVariables.customers.find(function(e){return Number(e.id)===Number(a)});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),$("#customer-notes").val(e.notes)),$("#select-customer").trigger("click")});var e=null;$("#filter-existing-customers").on("keyup",function(){e&&clearTimeout(e);var i=$(this).val().toLowerCase();e=setTimeout(function(){var n=$("#existing-customers-list"),e=GlobalVariables.baseUrl+"/index.php/backend_api/ajax_filter_customers",a={csrfToken:GlobalVariables.csrfToken,key:i};$("#loading").css("visibility","hidden"),$.post(e,a).done(function(e){n.empty(),e.forEach(function(a){$("
",{"data-id":a.id,text:a.first_name+" "+a.last_name}).appendTo(n),GlobalVariables.customers.filter(function(e){return Number(e.id)===Number(a.id)}).length||GlobalVariables.customers.push(a)})}).fail(function(e,a,t){n.empty(),GlobalVariables.customers.forEach(function(e,a){-1===e.first_name.toLowerCase().indexOf(i)&&-1===e.last_name.toLowerCase().indexOf(i)&&-1===e.email.toLowerCase().indexOf(i)&&-1===e.phone_number.toLowerCase().indexOf(i)&&-1===e.address.toLowerCase().indexOf(i)&&-1===e.city.toLowerCase().indexOf(i)&&-1===e.zip_code.toLowerCase().indexOf(i)&&-1===e.notes.toLowerCase().indexOf(i)||$("
",{"data-id":e.id,text:e.first_name+" "+e.last_name}).appendTo(n)})}).always(function(){$("#loading").css("visibility","")})},1e3)}),$("#select-service").on("change",function(){var t=$("#select-service").val();$("#select-provider").empty();var e=GlobalVariables.availableServices.find(function(e){return Number(e.id)===Number(t)}),a=e?e.duration:60,n=$("#start-datetime").datetimepicker("getDate");$("#end-datetime").datetimepicker("setDate",new Date(n.getTime()+6e4*a)),GlobalVariables.availableProviders.forEach(function(a){a.services.forEach(function(e){GlobalVariables.user.role_slug===Backend.DB_SLUG_PROVIDER&&Number(a.id)!==GlobalVariables.user.id||GlobalVariables.user.role_slug===Backend.DB_SLUG_SECRETARY&&-1===GlobalVariables.secretaryProviders.indexOf(a.id)||Number(e)===Number(t)&&$("#select-provider").append(new Option(a.first_name+" "+a.last_name,a.id))})})}),$("#select-provider").on("change",function(){var a,e;a=$("#select-provider").val(),(e=GlobalVariables.availableProviders.find(function(e){return Number(e.id)===Number(a)}))&&e.timezone&&$(".provider-timezone").text(GlobalVariables.timezones[e.timezone])}),$("#new-customer").on("click",function(){$("#manage-appointment").find("#customer-id, #first-name, #last-name, #email, #phone-number, #address, #city, #zip-code, #customer-notes").val("")})}e.resetAppointmentDialog=function(){var n=$("#manage-appointment");n.find("input, textarea").val(""),n.find(".modal-message").fadeOut(),n.find("#select-service").val(n.find("#select-service").eq(0).attr("value")),n.find("#select-provider").empty(),GlobalVariables.availableProviders.forEach(function(e,a){var t=n.find("#select-service").val();0