(function ($) {
    'use strict';

    $(document).ready(function () {
        $('#ld_qie_upload_file_form').on('submit', function (e) {
            e.preventDefault();

            var formData = new FormData(this);
            $.ajax({
                url: ajaxurl,
                type: 'POST',
                data: formData,
                cache: false,
                dataType: 'json',
                contentType: false,
                processData: false,
                beforeSend: function (jqXHR, settings) {
                    $('#ld_qie_loader_spinner').show();
                    $('#ld_qie_import_messages').html('');
                },
                success: function (data, textStatus, jqXHR) {

                    $('.ldcms-import-log').html(data.log);
                    console.log(data);
                    // WN_LD_QUIZ_IMPORT_EXPORT_ADMIN.step1.hide();
                    // WN_LD_QUIZ_IMPORT_EXPORT_ADMIN.step2.find('#ld_qie_quiz_listing_table').html(data.data.html);
                    // WN_LD_QUIZ_IMPORT_EXPORT_ADMIN.importedQuizzes = data.data.quiz_titles;
                    // WN_LD_QUIZ_IMPORT_EXPORT_ADMIN.workSheets = data.data.quiz_titles;

                    // WN_LD_QUIZ_IMPORT_EXPORT_ADMIN.initImportLDPostTypeSelect2('courses');
                    // WN_LD_QUIZ_IMPORT_EXPORT_ADMIN.initImportLDPostTypeSelect2('lessons_topics');
                    // WN_LD_QUIZ_IMPORT_EXPORT_ADMIN.initImportLDPostTypeSelect2('certificates');

                    // WN_LD_QUIZ_IMPORT_EXPORT_ADMIN.step2.show();

                    // $('#ld_qie_action').val('ld_qie_import_quizzes');
                    // getPagination('#ld_qie_quiz_listing_table table.ld_qie_table');
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    $('.ldcms-import-log').html(textStatus);
                    // WN_LD_QUIZ_IMPORT_EXPORT_ADMIN.showMessage(jqXHR.responseJSON.status, jqXHR.responseJSON.message);
                    // WN_LD_QUIZ_IMPORT_EXPORT_ADMIN.resetForm();
                },
                complete: function (jqXHR, textStatus) {
                    $('#ld_qie_loader_spinner').hide();
                }
            });
        });

        jQuery('#ldcms_import_file').each(function () {
            var $input = $(this),
                $label = $input.next('label'),
                labelVal = $label.html();

            $input.on('change', function (e) {
                var fileName = '';

                if (this.files && this.files.length > 1)
                    fileName = (this.getAttribute('data-multiple-caption') || '').replace('{count}', this.files.length);
                else if (e.target.value)
                    fileName = e.target.value.split('\\').pop();

                if (fileName)
                    $label.find('span').html(fileName);
                else
                    $label.html(labelVal);
            });

            // Firefox bug fix
            $input
                .on('focus', function () { $input.addClass('has-focus'); })
                .on('blur', function () { $input.removeClass('has-focus'); });
        });
    });

jQuery( document ).ready(function() {
        jQuery(".qst-mrk-tbla-crse-plnr svg, .qst-mrk-tbla-crse-plnr i").click(function(){
           jQuery(this).parent('label').next('p.description').fadeToggle();
        });

    });
    
jQuery(document).ready(function() {
    jQuery('.crse-lrn_woo_copy-button').click(function() {
      jQuery(this).children('span').toggleClass('dashicons-yes');
      var label = jQuery(this).prev('code').text();
      var temp = jQuery('<input>');
      jQuery('body').append(temp);
      temp.val(label).select();
      document.execCommand('copy');
      temp.remove();  
      setTimeout(function(){
        jQuery('.crse-lrn_woo_copy-button').children('span').removeClass('dashicons-yes');
        jQuery('.crse-lrn_woo_copy-button').children('span').addClass('dashicons-admin-page');       
    }, 1000);
    });

  /**
   * Start - Commented By Ejaz to fix JS error in calender
   */ 
  //   $('.grid').isotope({
  //       // options
  //       itemSelector: '.grid-item',
  //       layoutMode: 'fitRows'
  //     });
  /**
   * End - Commented By Ejaz to fix JS error in calender
   */ 

  });

  /**
   * Start - Commented By Ejaz to fix JS error in calender
   */ 
// external js: isotope.pkgd.js
// init Isotope
// var iso = new Isotope( '.grid', {
//     itemSelector: '.element-item',
//     layoutMode: 'fitRows',
//     getSortData: {
//       name: '.name',
//       symbol: '.symbol',
//       number: '.number parseInt',
//       category: '[data-category]',
//       weight: function( itemElem ) {
//         var weight = itemElem.querySelector('.weight').textContent;
//         return parseFloat( weight.replace( /[\(\)]/g, '') );
//       }
//     }
//   });
  
  // bind sort button click
  // var sortByGroup = document.querySelector('.sort-by-button-group');
  // sortByGroup.addEventListener( 'click', function( event ) {
  //   // only button clicks
  //   if ( !matchesSelector( event.target, '.button' ) ) {
  //     return;
  //   }
  //   var sortValue = event.target.getAttribute('data-sort-value');
  //   iso.arrange({ sortBy: sortValue });
  // });
  /**
  * End - Commented By Ejaz to fix JS error in calender
  */
  
  // change is-checked class on buttons
  var buttonGroups = document.querySelectorAll('.button-group');
  for ( var i=0; i < buttonGroups.length; i++ ) {
    buttonGroups[i].addEventListener( 'click', onButtonGroupClick );
  }
  
  function onButtonGroupClick( event ) {
    // only button clicks
    if ( !matchesSelector( event.target, '.button' ) ) {
      return;
    }
    var button = event.target;
    button.parentNode.querySelector('.is-checked').classList.remove('is-checked');
    button.classList.add('is-checked');
  }
  
$(window).on('load', function () {
        $(".ldcpp-loader-ovrly-pnl").hide().fadeOut("slow");;
       });


})(jQuery);
