"use strict";
function deleteRecord(url,title="",text=""){
    Swal.fire({
        title: title!="" ? title : "Are you sure?",
        text: text!="" ? text : "You won't be able to revert this!",
        icon: "warning",
        showCancelButton: true,
        confirmButtonText: "Yes, delete it!"
    }).then(function(result) {		
        if (result.value) {
			blockPage();
            window.location=url;
        }
    });
}

function signOutUser(url){
	Swal.fire({
        title: "Are you sure to sing out?",
        text: "",
        icon: "warning",
        showCancelButton: true,
        confirmButtonText: "Yes"
    }).then(function(result) {		
        if (result.value) {
			blockPage();
            window.location=url;
        }
    });
}

function notifyAlert(nType,nMsg,nTitle="",nUrl="",nNewTab=true){
	var config = {};
	config.success = {type:'success', icon:'far fa-check-circle'};
	config.danger = {type:'danger', icon:'fas fa-exclamation-circle'};
	config.warning = {type:'warning', icon:'fas fa-exclamation-circle'};
	config.info = {type:'info', icon:'fas fa-info-circle'};
	config.primary = {type:'primary', icon:'fas fa-info-circle'};
	config.dark = {type:'dark', icon:'fas fa-info-circle'};
	
	var content = {};
	if(nTitle != ""){
		content.title = nTitle;
	}	
	content.message = nMsg;
	content.icon = 'icon ' + config[nType].icon;
	if(nUrl != ""){
		content.url = nUrl;
		if(nNewTab){ content.target = '_blank' };
	}	
	var notify = $.notify(content, {
		type: config[nType].type, // success, danger, warning, info, primary, dark
		allow_dismiss: true,
		newest_on_top: true,
		mouse_over:  true,
		showProgressbar:  false,
		spacing: 10,
		timer: 2000,
		placement: {
			from: 'top',
			align: 'right'
		},
		offset: {
			x: 30,
			y: 30
		},
		delay: 1000,
		z_index: 10000,
		animate: {
			enter: 'animate__animated animate__bounceInDown',
			exit: 'animate__animated animate__bounceOutUp'
		}
	});
}

function blockPage(){
	KTApp.blockPage({
	  overlayColor: '#000000',
	  state: 'danger',
	  message: 'Please wait...'
	});
}

function unblockPage(){
	KTApp.unblockPage();
}

function blockUI(id){
	KTApp.block('#'+id, {
		overlayColor: '#000000',
		state: 'danger',
		message: 'Please wait...'
	});
}

function unblockUI(id){
	KTApp.unblock('#'+id);
}

function loadModal(size='lg'){
	var sizeClass = 'modal-' + size;
	$('#popup_wrapper_modal_box').addClass(sizeClass);
	$('#popup_wrapper_model_content').text('Loading...');
	$('#popup_wrapper_modal').modal('show');
}

function closeModal(){
  $('#popup_wrapper_modal').modal('hide'); 
}

function genAlnumStr(fromFldID, toFldID){
	var str = $('#'+fromFldID).val();
	var url_fltr_1 = str.replace(/  */g, '_');
	var url_fltr_2 = url_fltr_1.replace(/[^0-9a-zA-Z_]/g, '');
	$('#'+toFldID).val(url_fltr_2.toLowerCase());
}

var KTBootstrapDatepicker = function () {

    var arrows;
    if (KTUtil.isRTL()) {
        arrows = {
            leftArrow: '<i class="la la-angle-right"></i>',
            rightArrow: '<i class="la la-angle-left"></i>'
        }
    } else {
        arrows = {
            leftArrow: '<i class="la la-angle-left"></i>',
            rightArrow: '<i class="la la-angle-right"></i>'
        }
    }
    
    // Private functions
    var demos = function () {
		$('.c_datepicker').prop('readonly',true);
		$('.c_datepicker').datepicker({
            changeMonth: true,
			changeYear: true,
			dateFormat: 'dd-mm-yy'
        });
        // input group layout 
       /* $('.c_datepicker, .c_datepicker_validate').datepicker({
            rtl: KTUtil.isRTL(),
            todayHighlight: true,
			format: "dd-mm-yyyy",
            orientation: "bottom left",
            templates: arrows
        });

        // input group layout for modal demo
        $('#c_datepicker_modal').datepicker({
            rtl: KTUtil.isRTL(),
            todayHighlight: true,
            orientation: "bottom left",
            templates: arrows
        });*/
    }

    return {
        // public functions
        init: function() {
            demos(); 
        }
    };
}();

var KTBootstrapTimepicker = function () {

	var demos = function () {
		$('.c_timepicker').prop('readonly',true);
		$('.c_timepicker').timepicker({
			minuteStep: 1,
            showSeconds: false,
            showMeridian: true,
			template: 'dropdown'
		});
	}
	return {
	  init: function() {
	   demos();
	  }
	};
}();

jQuery(document).ready(function() {    
    KTBootstrapDatepicker.init();
	KTBootstrapTimepicker.init();
});