(function($) {
	"use strict"


var base_url = $('#base_url').attr('href');
var csrf_value = $('#csrf_value').attr('href');
var get_rtl = $('#rtl').data('id');

if(get_rtl=='rtl'){
  var rtl = true;
}else{
  var get_rtl = false;
}

$(function () {
  var input = $("#phone");
  var code = "+880"; // Assigning value from model.
  input.val(code);
 input.intlTelInput({
    autoHideDialCode: true,
    autoPlaceholder: "ON",
    dropdownContainer: document.body,
    formatOnDisplay: true,
    hiddenInput: "full_number",
    initialCountry: "auto",
    nationalMode: true,
    placeholderNumberType: "MOBILE",
    preferredCountries: ['US'],
    separateDialCode: true
  });

  $(document).on('keyup','#phone',function(){
    $('.country_code').val(input.intlTelInput("getSelectedCountryData").iso2);
    $('.dial_code').val(input.intlTelInput("getSelectedCountryData").dialCode);
  });


 });




$(function () {

  $(document).on('submit', '.serviceRegistration', function (e) {
    e.preventDefault();
    var $form = $(this);
    var url = $form.attr('action');
    var data = $form.serialize();
    $.ajax({
      type: 'post',
      url: url,
      dataType: "json",
      processData: true,
      data: data,
      beforeSend: function() {
        $('.country_code').val($('.phone').intlTelInput("getSelectedCountryData").iso2);
        $('.dial_code').val($('.phone').intlTelInput("getSelectedCountryData").dialCode);
        send_btn_loader(true);
      },
      success: function (json) {
        if(json.st ==1){
          $('.serviceRegistration')[0].reset(); 
          $('.alertMsg').html(json.msg).slideDown();
          setTimeout(function(){ 
            $('.serviceUserForm').slideUp();
            $('.paymentFormarea').slideDown(); 
          }, 1000);
          send_btn_loader(false);
        }else{
          send_btn_loader(false);
          $('.alertMsg').html(json.msg).slideDown();
        }
      },
      error: function(jqXHR, textStatus, errorThrown) {
        $('.alertMsg').html(`<div class="alert alert-danger alert-dismissible">
          <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
          <strong>Sorry ! </strong> ${textStatus, errorThrown}
          </div>`);
        console.log(textStatus, errorThrown);
        send_btn_loader(false);
      }
    });

  });

});  

$(document).on('submit', '.serviceLogin', function (e) {
    e.preventDefault();
    var $form = $(this);
    var url = $form.attr('action');
    var data = $form.serialize();
    $.ajax({
      type: 'post',
      url: url,
      dataType: "json",
      processData: true,
      data: data,
      beforeSend: function() {
        send_btn_loader(true);
      },
      success: function (json) {
        if(json.st ==1){
          $('.serviceLogin')[0].reset(); 
          $('.alertMsg').html(json.msg).slideDown();
          setTimeout(function(){ 
            $('.serviceUserForm').slideUp();
            $('.paymentFormarea').slideDown(); 
          }, 1000);
          send_btn_loader(false);
        }else{
          send_btn_loader(false);
          $('.alertMsg').html(json.msg).slideDown();
        }
      },
      error: function(jqXHR, textStatus, errorThrown) {
        $('.alertMsg').html(`<div class="alert alert-danger alert-dismissible">
          <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
          <strong>Sorry ! </strong> ${textStatus, errorThrown}
          </div>`);
        console.log(textStatus, errorThrown);
        send_btn_loader(false);
      }
    });

  });




function send_btn_loader(type){
  var $this = $('.submitBtn');
  if(type==true){
       $this.addClass('btn-spinner');
       $this.attr('disabled', true);
       setTimeout(function(){ $(".alertMsg").slideUp() }, 3000);
    }else{
      $this.removeClass('btn-spinner');
        $this.prop('disabled', false);
        setTimeout(function(){ $(".alertMsg").slideUp() }, 3000);
    }
}






$(document).ready(function(){
    $('a[data-toggle="tab"]').on('shown.bs.tab', function(e){
      var target = $(this).attr('href');
      $('.tab-content').find(target).addClass('active show').removeClass('fade');
      var previousTab = $(e.relatedTarget).attr('href');
      $('.tab-content').find(previousTab).removeClass('active show').addClass('fade');
      
    });
});


$(document).ready(function(){
  $(document).on('click','.modalBtn',function(){
    $('#paypal_login').html('');
    $('#stripe_login').html('');
    $('#razorpay_login').html('');
    $('#offline_login').html('');
    var type = $(this).data('type');
    var user = $(this).data('user');
    var url = `${base_url}service/load_modal/${user}`;
    $(`#${type}_login`).load(url);
    $(`#${type}`).modal('show');
  });
  
});






})(jQuery);