extends layout

block content
  include ./includes/common.pug
  script.
    var setting_maxTxCount = parseInt("#{settings.api_page.public_apis.ext.getlasttxs.max_items_per_query}");
    var setting_txPerPage = parseInt("#{settings.index_page.transaction_table.items_per_page}");
    var lengthMenuOptsAdd = !{JSON.stringify(settings.index_page.transaction_table.page_length_options)};
    var lengthMenuOpts = [];
    var addedLength = false;
    for (i = 0; i < lengthMenuOptsAdd.length; i++) {
      if (setting_maxTxCount >= lengthMenuOptsAdd[i]) {
        if (!addedLength) {
          if (lengthMenuOptsAdd[i] > setting_txPerPage) {
            lengthMenuOpts.push(setting_txPerPage);
            addedLength = true;
          }
        }

        lengthMenuOpts.push(lengthMenuOptsAdd[i]);

        if (!addedLength) {
          if (lengthMenuOptsAdd[i] > setting_txPerPage)
            lengthMenuOpts.push(setting_txPerPage);
          if (lengthMenuOptsAdd[i] == setting_txPerPage || lengthMenuOptsAdd[i] > setting_txPerPage)
            addedLength = true;
        }
      }
    }
    if (!addedLength && setting_txPerPage <= setting_maxTxCount && setting_txPerPage != lengthMenuOpts[lengthMenuOpts.length - 1])
      lengthMenuOpts.push(setting_txPerPage);
    if (!addedLength && setting_txPerPage > setting_maxTxCount && setting_maxTxCount != lengthMenuOpts[lengthMenuOpts.length - 1])
      lengthMenuOpts.push(setting_maxTxCount);
    if (setting_maxTxCount < setting_txPerPage)
      var displayLengthMax = setting_maxTxCount;
    else
      var displayLengthMax = setting_txPerPage;
    $(document).ready(function() {
      var rtable = $('#recent-table').dataTable({
        autoWidth: false,
        searching: false,
        ordering: false,
        responsive: false,
        lengthChange: true,
        processing: true,
        serverSide: true,
        iDisplayLength: displayLengthMax,
        lengthMenu: lengthMenuOpts,
        scrollX: true,
        ajax: {
          url: '/ext/getlasttxs/0',
          beforeSend: function(jqXHR, settings) {
            settings.url = settings.url.substring(0, settings.url.indexOf('?')) + '/' + getParameterByName('start', settings.url) + '/' + getParameterByName('length', settings.url) + '/internal';
            return true;
          }
        },
        language: {
          paginate: {
            previous: '<',
            next: '>'
          }
        },
        rowCallback: function(row, data, index) {
          var blockindex = data[0]; //variables for better readability
          var blockhash = data[1]; //variables for better readability
          var txhash = data[2]; //variables for better readability
          var outputs = data[3]; //variables for better readability
          var amount = Number(data[4]).toLocaleString('en',{'minimumFractionDigits':2,'maximumFractionDigits':8,'useGrouping':true}); //variables for better readability
          var amountParts = amount.split('.');
          var amount = amountParts[0] + '.<span class="decimal">' + amountParts[1] + '</span>';
          var timestamp = data[5];
          $("td:eq(0)", row).html('<a href="/tx/' + txhash + '"><span class="fa fa-eye" data-bs-toggle="tooltip" data-bs-placement="top" title="#{settings.locale.view_tx}"></span></a>').addClass('text-center d-table-cell d-md-none');
          $("td:eq(1)", row).html('<a href="/block/' + blockhash + '">' + blockindex + '</a>');
          $("td:eq(2)", row).html('<a href="/tx/' + txhash + '">' + txhash + '</a>').addClass("text-center breakWord d-none d-md-table-cell");
          $("td:eq(3)", row).html(outputs).addClass("text-center d-none d-sm-table-cell");
          $("td:eq(4)", row).html(amount);
          $("td:eq(5)", row).html('<span' + (#{settings.shared_pages.date_time.enable_alt_timezone_tooltips} == true ? ' data-bs-toggle="tooltip" data-bs-placement="auto" title="' + format_unixtime(timestamp, true) + '"' : '') + '>' + format_unixtime(timestamp) + '</span>').addClass('text-center');
        },
        fnDrawCallback: function(settings) {
          fixDataTableColumns();
          fixFooterHeightAndPosition();
          enableTooltips();
        }
      });
      var setting_reload_table_seconds = parseInt("#{settings.index_page.transaction_table.reload_table_seconds}");
      if (setting_reload_table_seconds > 0) {
        setInterval( function () {
          rtable.api().ajax.reload(null, false);
        }, (setting_reload_table_seconds * 1000) );
      }

      if ('#{settings.index_page.page_header.show_last_updated}' == 'true') {
        var lastUpdatedDate = #{(last_updated == null || last_updated == '0' ? 0 : last_updated)};

        if (lastUpdatedDate != 0) {
          $('span#lastUpdatedDate').html(' ' + format_unixtime(lastUpdatedDate));

          if (#{settings.shared_pages.date_time.enable_alt_timezone_tooltips} == true) {
            $('span#lastUpdatedDate').attr('data-bs-toggle', 'tooltip').attr('data-bs-placement', 'auto').attr('title', format_unixtime(lastUpdatedDate, true));
            enableTooltips();
          }
        } else
          $('span#lastUpdatedDate').html(' N/A');
      }
      if (#{settings.shared_pages.page_header.page_title_image.enable_animation} == true && #{settings.index_page.page_header.show_img} == true)
        startRotateElement('img#header-img');
    });
  if error !== null
    .col-12
      .alert.alert-danger.alert-dismissible.fade.show(role='alert')
        button.btn-close(type='button', data-bs-dismiss='alert')
        .cardSpacer
          span.fas.fa-exclamation-circle(style='margin-right:5px')
          strong #{settings.locale.ex_error}
        div #{error}
  .col-md-12.cardSpacer
    if settings.index_page.page_header.show_img == true || settings.index_page.page_header.show_title == true || settings.index_page.page_header.show_last_updated == true || settings.index_page.page_header.show_description == true
      #page-header-container(style='align-items:' + (settings.index_page.page_header.show_img == true && settings.index_page.page_header.show_title == true && settings.index_page.page_header.show_last_updated == true && settings.index_page.page_header.show_description == true ? 'flex-start' : 'center'))
        if settings.index_page.page_header.show_img == true
          #header-img-container
            img#header-img(src=(settings.shared_pages.page_header.page_title_image == null || settings.shared_pages.page_header.page_title_image.image_path == null || settings.shared_pages.page_header.page_title_image.image_path == '' ? '/img/page-title-img.png' : settings.shared_pages.page_header.page_title_image.image_path))
        #page-title-container
          if settings.index_page.page_header.show_title == true
            h3#page-title #{settings.locale.ex_title.replace('{1}', settings.coin.name)}
          if settings.index_page.page_header.show_last_updated == true
            if settings.index_page.page_header.show_title != true && settings.index_page.page_header.show_description != true
              #page-title-container
                .sub-page-header
                  span.fw-bold=settings.locale.last_updated + ':'
                  span.text-muted#lastUpdatedDate
            else
              .sub-page-header(style='margin-bottom:' + (settings.index_page.page_header.show_description == true ? '5' : '0') + 'px')
                span.fw-bold=settings.locale.last_updated + ':'
                span.text-muted#lastUpdatedDate
          if settings.index_page.page_header.show_description == true
            if settings.index_page.page_header.show_title != true && settings.index_page.page_header.show_last_updated != true
              #page-title-container
                .sub-page-header.text-muted=settings.locale.ex_description.replace('{1}', settings.coin.name)
            else
              .sub-page-header.text-muted=settings.locale.ex_description.replace('{1}', settings.coin.name)
      .cardSpacer.clearfix
    .card.card-default.border-0.cardSpacer
      .card-header
        strong #{settings.locale.ex_latest_transactions}
      table#recent-table.table.table-bordered.table-striped.table-paging.table-hover
        - var theadClasses = [];
        if settings.shared_pages.table_header_bgcolor != null && settings.shared_pages.table_header_bgcolor != ''
          - theadClasses.push('table-' + settings.shared_pages.table_header_bgcolor);
        thead
          tr(class=theadClasses)
            th.d-table-cell.d-md-none
            th.text-center #{settings.locale.ex_block}
            th.text-center.d-none.d-md-table-cell #{settings.locale.tx_hash}
            th.text-center.d-none.d-sm-table-cell #{settings.locale.tx_recipients}
            th.text-center #{settings.locale.mkt_amount}
              span.small.fw-normal  (#{settings.coin.symbol})
            th.text-center #{settings.locale.timestamp}
        tbody.text-center