$( document ).ready(function($) {
    let activePast = true;

    const changeActivePast = () => {
        if(activePast == true) {
            activePast = false;
            $('.af2_post_table_body .af2_post_table_row').each((i, el) => {
                let id = $(el).attr('id');
                if(id != undefined) {
                    let datum = $('.af2_post_table_body .af2_post_table_row#' + id +' .af2_post_table_content[data-searchfilter="Datum"]').data('searchvalue');
                    let zeit = $('.af2_post_table_body .af2_post_table_row#' + id +' .af2_post_table_content[data-searchfilter="Zeit"]').data('searchvalue');
    
                    let datums = [datum.substr(0, 2), datum.substr(3, 2), datum.substr(6, 4)];
                    let zeits = [zeit.substr(0, 2), zeit.substr(3, 2)];
                    let final = datums[2] + '' + datums[1] + '' + datums[0] + '' + zeits[0] + '' + zeits[1];
    
                    let date = new Date()
    
                    let day = date.getDay();
                    let month = date.getMonth() + 1;
                    let year = date.getFullYear();
                    let hour = date.getHours();
                    let minute = date.getMinutes();
    
                    day = (day < 10 ? '0' : '') + day;
                    month = (month < 10 ? '0' : '') + month;
                    hour = (hour < 10 ? '0' : '') + hour;
                    minute = (minute < 10 ? '0' : '') + minute;
    
                    let final2 = year + '' + month + '' + day + '' + hour + '' + minute;
                    
                    if(final < final2) $('.af2_post_table_body .af2_post_table_row#' + id).addClass('af2_hide');
                    if(final < final2) $('.af2_post_table_body .af2_post_table_row#' + id).addClass('af2_table_highlight');

                    // console.log($('.af2_post_table_body .af2_post_table_content[data-searchfilter="Titel"]').data('searchvalue') + ' - ' + final + ' : ' + final2);
                }
            });
        }
        else {
            activePast = true;
            $('.af2_post_table_row.af2_hide').each((i, el) => {
                $('#'+$(el).attr('id')).removeClass('af2_hide');
            });
        } 
    }

    $(document).on('click', '#af2_show_outdated', changeActivePast );

    changeActivePast();
});
