<script src="../Assets/node_modules/jquery/jquery-3.2.1.min.js"></script>
<script src="../Assets/node_modules/popper/popper.min.js"></script>
<script src="../Assets/node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="../Assets/js/perfect-scrollbar.jquery.min.js"></script>
<script src="../Assets/js/waves.js"></script>
<script src="../Assets/js/sidebarmenu.js"></script>
<script src="../Assets/node_modules/sticky-kit-master/dist/sticky-kit.min.js"></script>
<script src="../Assets/node_modules/sparkline/jquery.sparkline.min.js"></script>
<script src="../Assets/js/custom.min.js"></script>

<script src="../Assets/node_modules/datatables.net/js/jquery.dataTables.min.js"></script>
<script src="../Assets/node_modules/datatables.net-bs4/js/dataTables.responsive.min.js"></script>

<script src="../Assets/node_modules/raphael/raphael-min.js"></script>
<script src="../Assets/node_modules/morrisjs/morris.min.js"></script>
<script src="../Assets/node_modules/jquery-sparkline/jquery.sparkline.min.js"></script>

<script src="../Assets/node_modules/toast-master/js/jquery.toast.js"></script>
<script src="../Assets/node_modules/sweetalert2/dist/sweetalert2.all.min.js"></script>
<script src="../Assets/js/mygold-alert.js"></script>

<script src="../Assets/node_modules/moment/moment.js"></script>
<script src="../Assets/node_modules/bootstrap-material-datetimepicker/js/bootstrap-material-datetimepicker.js"></script>
<script src="../Assets/node_modules/clockpicker/dist/jquery-clockpicker.min.js"></script>
<script src="../Assets/node_modules/bootstrap-datepicker/bootstrap-datepicker.min.js"></script>
<script src="../Assets/node_modules/timepicker/bootstrap-timepicker.min.js"></script>
<script src="../Assets/node_modules/bootstrap-daterangepicker/daterangepicker.js"></script>

<script src="../Assets/node_modules/html5-editor/wysihtml5-0.3.0.js"></script>
<script src="../Assets/node_modules/html5-editor/bootstrap-wysihtml5.js"></script>

<script src="https://cdn.datatables.net/buttons/1.5.1/js/dataTables.buttons.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.5.1/js/buttons.flash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/pdfmake.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/vfs_fonts.js"></script>
<script src="https://cdn.datatables.net/buttons/1.5.1/js/buttons.html5.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.5.1/js/buttons.print.min.js"></script>

<script src="../Assets/node_modules/summernote/dist/summernote-bs4.min.js"></script>

<script>
$(function () {

  // ------------------------------------
  // Bootstrap Material Datepicker (safe)
  // ------------------------------------
  if ($.fn.bootstrapMaterialDatePicker) {
    if ($('#mdate').length) $('#mdate').bootstrapMaterialDatePicker({ weekStart: 0, time: false });
    if ($('#timepicker').length) $('#timepicker').bootstrapMaterialDatePicker({ format: 'HH:mm', time: true, date: false });
    if ($('#date-format').length) $('#date-format').bootstrapMaterialDatePicker({ format: 'dddd DD MMMM YYYY - HH:mm' });
    if ($('#min-date').length) $('#min-date').bootstrapMaterialDatePicker({ format: 'DD/MM/YYYY HH:mm', minDate: new Date() });
  }

  // -------------
  // Clockpicker
  // -------------
  if ($.fn.clockpicker) {
    if ($('#single-input').length) {
      $('#single-input').clockpicker({
        placement: 'bottom',
        align: 'left',
        autoclose: true,
        'default': 'now'
      });
    }
    if ($('.clockpicker').length) {
      $('.clockpicker').clockpicker({ donetext: 'Done' });
    }
  }

  // -------------
  // Datepicker
  // -------------
  if ($.fn.datepicker) {
    $('.mydatepicker, #datepicker').datepicker();
    if ($('#datepicker-autoclose').length) {
      $('#datepicker-autoclose').datepicker({ autoclose: true, todayHighlight: true });
    }
    if ($('#date-range').length) {
      $('#date-range').datepicker({ toggleActive: true });
    }
    if ($('#datepicker-inline').length) {
      $('#datepicker-inline').datepicker({ todayHighlight: true });
    }
  }

  // ----------------
  // Date Range Picker
  // ----------------
  if ($.fn.daterangepicker) {
    if ($('.daterange').length) $('.daterange').daterangepicker();

    if ($('.datetime').length) {
      $('.datetime').daterangepicker({
        timePicker: true,
        timePickerIncrement: 30,
        locale: { format: 'MM/DD/YYYY h:mm A' }
      });
    }

    if ($('.timeseconds').length) {
      $('.timeseconds').daterangepicker({
        timePicker: true,
        timePickerIncrement: 30,
        timePicker24Hour: true,
        timePickerSeconds: true,
        locale: { format: 'MM-DD-YYYY h:mm:ss' }
      });
    }

    if ($('.singledate').length) $('.singledate').daterangepicker({ singleDatePicker: true, showDropdowns: true });
    if ($('.autoapply').length) $('.autoapply').daterangepicker({ autoApply: true });
    if ($('.linkedCalendars').length) $('.linkedCalendars').daterangepicker({ linkedCalendars: false });
    if ($('.dateLimit').length) $('.dateLimit').daterangepicker({ dateLimit: { days: 7 } });
    if ($('.showdropdowns').length) $('.showdropdowns').daterangepicker({ showDropdowns: true });
    if ($('.showweeknumbers').length) $('.showweeknumbers').daterangepicker({ showWeekNumbers: true });
    if ($('.drops').length) $('.drops').daterangepicker({ drops: "up" });

    if ($('.buttonClass').length) {
      $('.buttonClass').daterangepicker({
        drops: "up",
        buttonClasses: "btn",
        applyClass: "btn-info",
        cancelClass: "btn-danger"
      });
    }

    if ($('.input-daterange-datepicker').length) {
      $('.input-daterange-datepicker').daterangepicker({
        buttonClasses: ['btn', 'btn-sm'],
        applyClass: 'btn-danger',
        cancelClass: 'btn-inverse'
      });
    }

    if ($('.input-daterange-timepicker').length) {
      $('.input-daterange-timepicker').daterangepicker({
        timePicker: true,
        format: 'MM/DD/YYYY h:mm A',
        timePickerIncrement: 30,
        timePicker12Hour: true,
        timePickerSeconds: false,
        buttonClasses: ['btn', 'btn-sm'],
        applyClass: 'btn-danger',
        cancelClass: 'btn-inverse'
      });
    }

    if ($('.input-limit-datepicker').length) {
      $('.input-limit-datepicker').daterangepicker({
        format: 'MM/DD/YYYY',
        minDate: '06/01/2015',
        maxDate: '06/30/2015',
        buttonClasses: ['btn', 'btn-sm'],
        applyClass: 'btn-danger',
        cancelClass: 'btn-inverse',
        dateLimit: { days: 6 }
      });
    }
  }

  // ----------
  // WYSIHTML5
  // ----------
  if ($.fn.wysihtml5 && $('.textarea_editor').length) {
    $('.textarea_editor').wysihtml5();
  }

  // ----------
  // Summernote
  // ----------
  if ($.fn.summernote) {
    if ($('.summernote').length) {
      $('.summernote').summernote({
        height: 350,
        minHeight: null,
        maxHeight: null,
        focus: false
      });
    }

    if ($('.inline-editor').length) {
      $('.inline-editor').summernote({ airMode: true });
    }

    window.edit = function () { $(".click2edit").summernote(); };
    window.save = function () { $(".click2edit").summernote('destroy'); };
  }

  // ----------
  // DataTables
  // ----------
  if ($.fn.DataTable) {
    if ($('#myTable').length) $('#myTable').DataTable();

    if ($('#example').length) {
      var table = $('#example').DataTable({
        columnDefs: [{ visible: false, targets: 2 }],
        order: [[1, 'asc']],
        displayLength: 25,
        drawCallback: function (settings) {
          var api = this.api();
          var rows = api.rows({ page: 'current' }).nodes();
          var last = null;

          api.column(2, { page: 'current' }).data().each(function (group, i) {
            if (last !== group) {
              $(rows).eq(i).before('<tr class="group"><td colspan="5">' + group + '</td></tr>');
              last = group;
            }
          });
        }
      });

      $('#example tbody').on('click', 'tr.group', function () {
        var currentOrder = table.order()[0];
        if (currentOrder[0] === 2 && currentOrder[1] === 'asc') {
          table.order([2, 'desc']).draw();
        } else {
          table.order([2, 'asc']).draw();
        }
      });
    }

    if ($('#config-table').length) {
      $('#config-table').DataTable({ responsive: true });
    }

    if ($('#example23').length) {
      $('#example23').DataTable({
        dom: 'Bfrtip',
        buttons: ['copy', 'csv', 'excel', 'pdf', 'print']
      });

      $('.buttons-copy, .buttons-csv, .buttons-print, .buttons-pdf, .buttons-excel')
        .addClass('btn btn-primary mr-1');
    }
  }
});
</script>
