'use strict';

// Datatable (jquery)
$(function () {
  // Build language configuration from pageData if available
  var languageConfig = {};
  if (typeof pageData !== 'undefined' && pageData.labels) {
    languageConfig = {
      search: '',
      searchPlaceholder: pageData.labels.searchPlaceholder || 'Search...',
      processing: pageData.labels.processing || 'Processing...',
      lengthMenu: pageData.labels.lengthMenu || 'Show _MENU_ entries',
      info: pageData.labels.info || 'Showing _START_ to _END_ of _TOTAL_ entries',
      infoEmpty: pageData.labels.infoEmpty || 'No entries to show',
      infoFiltered: pageData.labels.infoFiltered || '(filtered from _MAX_ total entries)',
      emptyTable: pageData.labels.emptyTable || 'No data available',
      zeroRecords: pageData.labels.zeroRecords || 'No matching records found',
      paginate: {
        first: pageData.labels.paginate?.first || 'First',
        last: pageData.labels.paginate?.last || 'Last',
        next: pageData.labels.paginate?.next || 'Next',
        previous: pageData.labels.paginate?.previous || 'Previous'
      }
    };
  }

  $('#datatable').DataTable({
    order: [[0, 'desc']],
    language: languageConfig
  });

  $('.datatable').DataTable({
    order: [[0, 'desc']],
    language: languageConfig
  });
});
