@yield('main')

<script>
	$(function(){
	
		$('.modal-date').flatpickr({
			dateFormat: 'd M Y'
		});
	
		$('.modal-time').flatpickr({
			noCalendar: true,
			enableTime: true,
			dateFormat: "h:i K",
		});
	
		$('.modal-form').on('submit', function(event){
	
			event.preventDefault();
			var self=$(this);
	
			$('.btn-submit').prop('disabled', true);
	
			   $(self).waitMe({
				effect: 'facebook',
				text: 'Please! Wait ...'
			});
			
			$(this).ajaxSubmit({
			  success:function(res){
	
				   $(self).waitMe('hide');
	
				if(res.msg){
					new Noty({
						theme:'sunset',
						text: res.msg,
						type: 'success',
						timeout:1000,
						callbacks:{
							afterClose:function(){  
								var replace_content=self.find('input[name=replace_content]').val();
	
								if(replace_content){
	
									url=self.find("input[name='replace_content']").data('replace');
	
									$(replace_content).waitMe({
										effect: 'facebook',
										text: 'Please! Wait ...'
									});
																
									$(replace_content).load(url, null, function(){
	
										$(replace_content).waitMe('hide');
	
									});
	
									$('#modal_page').modal('hide');
	
								}else window.location.reload();
	
							}
						}
					}).show();
				}
	
			  },
			  error:function(res){
	
				  $(self).waitMe('hide');
	
				  let msg="Request submission failed. Please! try again later.";
	
				if(res.responseJSON && res.responseJSON.msg){
					msg=res.responseJSON.msg;
				}
	
				   new Noty({
					theme:'sunset',
					text: msg,
					type: 'error',
					timeout:3000,
					callbacks:{
						afterClose:function(){
							$('.btn-submit').prop('disabled', false);
						}
					}
				}).show();
	
			  }
			});
	
		  });
	});
	</script>
	
