<div class="col card--ui" id="card--dashboard">


    <header id="title--section" style="display:none !important"
        class="d-flex align-items-center justify-content-between">
        <div class="title--section_name d-flex align-items-center justify-content-between">
            <i class="ico--ui title_section utenti me-2"></i>
            <h2 class="primary">Iscritti ai corsi</h2>
        </div>

    </header>

    <a class="btn--ui lightGrey" href="/course_member_two?type={{$type}}"><i class="fa-solid fa-arrow-left"></i></a><br>

    @if ($course)
    @php
        $courseDiscipline = $course->discipline?->name ?? '';
        $courseName = $course->name ?? 'Corso Sconosciuto';
        $levelName = is_object($course->level) ? $course->level->name : '';
        $frequencyName = is_object($course->frequency) ? $course->frequency->name : '';

        $courseInfoParts = [];
        if ($levelName) $courseInfoParts[] = $levelName;
        if ($frequencyName) $courseInfoParts[] = $frequencyName;

        $courseInfo = implode(' - ', $courseInfoParts);
    @endphp
        <h3>@if($courseDiscipline){{$courseDiscipline}} - @endif{{$courseName}}</h3>
        <p>{{$courseInfo}}</p>
    @endif


    <div class="showFilter" style="display:none" wire:ignore.self>
        <hr size="1">
        <div class="row g-3">
            <div class="col-md-2">
                <div class="row">
                    <div class="col-md-12" style="margin-bottom:10px;">
                        <b>Corso</b>
                    </div>
                    <div class="col-12">
                        <select class="form-select filterCourse" multiple="multiple">
                            @foreach($courses as $c)
                                <option value="{{$c}}">{{$c}}
                            @endforeach
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-md-2">
                <div class="row">
                    <div class="col-md-12" style="margin-bottom:10px;">
                        <b>Livello</b>
                    </div>
                    <div class="col-12">
                        <select class="form-select filterLevel" multiple="multiple">
                            @foreach($course_levels as $c)
                                <option value="{{$c->id}}">{{$c->name}}
                            @endforeach
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-md-2">
                <div class="row">
                    <div class="col-md-12" style="margin-bottom:10px;">
                        <b>Frequenza</b>
                    </div>
                    <div class="col-12">
                        <select class="form-select filterFrequency" multiple="multiple">
                            @foreach($course_frequencies as $c)
                                <option value="{{$c->id}}">{{$c->name}}
                            @endforeach
                        </select>
                    </div>
                </div>
            </div>
            {{-- <div class="col-md-2">
                <div class="row">
                    <div class="col-md-12" style="margin-bottom:10px;">
                        <b>Tipologia</b>
                    </div>
                    <div class="col-12">
                        <select class="form-select filterType" multiple="multiple">
                            @foreach($course_types as $c)
                                <option value="{{$c->id}}">{{$c->name}}
                            @endforeach
                        </select>
                    </div>
                </div>
            </div> --}}
            <div class="col-md-2">
                <div class="row">
                    <div class="col-md-12" style="margin-bottom:10px;">
                        <b>Durata</b>
                    </div>
                    <div class="col-12">
                        <select class="form-select filterDuration" multiple="multiple">
                            @foreach($course_durations as $c)
                                <option value="{{$c->id}}">{{$c->name}}
                            @endforeach
                        </select>
                    </div>
                </div>
            </div>
        </div>
        <div class="row g-3 mt-1">
            <div class="col-md-3">
                <div class="row">
                    <div class="col-md-12" style="margin-bottom:10px;">
                        <b>Giorni</b>
                    </div>
                    <div class="col-12">
                        <select class="form-select filterDays" multiple="multiple">
                            <option value="lun">Lunedì
                            <option value="mar">Martedì
                            <option value="mer">Mercoledì
                            <option value="gio">Giovedì
                            <option value="ven">Venerdì
                            <option value="sab">Sabato
                            <option value="dom">Domenica
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-md-3">
                <div class="row">
                    <div class="col-md-12" style="margin-bottom:10px;">
                        <b>Orari</b>
                    </div>
                    <div class="col-12">
                        <select class="form-select filterHours" multiple="multiple">
                            @for($c = 6; $c <= 23; $c++)
                                <option value="{{str_pad($c, 2, "0", STR_PAD_LEFT)}}:00">
                                    {{str_pad($c, 2, "0", STR_PAD_LEFT)}}:00
                                <option value="{{str_pad($c, 2, "0", STR_PAD_LEFT)}}:30">
                                    {{str_pad($c, 2, "0", STR_PAD_LEFT)}}:30
                            @endfor
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-md-3">
                <div class="row">
                    <div class="col-md-12" style="margin-bottom:10px;">
                        <b>Anno</b>
                    </div>
                    <div class="col-12">
                        <select class="form-select filterYear">
                            <option value="">--Seleziona--
                                @foreach($course_years as $c)
                                    <option value="{{$c}}">{{$c}}
                                @endforeach
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-md-3">
                <div class="row">
                    <div class="col-md-12" style="margin-bottom:10px;">
                        <b>Pagamento iscrizione</b>
                    </div>
                    <div class="col-12">
                        <select class="form-select filterSubscription">
                            <option value="">--Seleziona--
                            <option value="1">Pagata
                            <option value="0">Non Pagata
                        </select>
                    </div>
                </div>
            </div>
        </div>
        <div class="row g-3 mt-1">
            <div class="col-md-3">
                <div class="row">
                    <div class="col-md-12" style="margin-bottom:10px;">
                        <b>Tipologia di tesseramento</b>
                    </div>
                    <div class="col-12">
                        <select class="form-select filterCards" multiple="multiple">
                            @foreach(getCards() as $card)
                                <option value="{{$card->id}}">{{$card->name}}
                            @endforeach
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-md-3">
                <div class="row">
                    <div class="col-md-12" style="margin-bottom:10px;">
                        <b>Stato tesseramento</b>
                    </div>
                    <div class="col-12">
                        <select class="form-select filterStatus" multiple="multiple">
                            <option value="2">Attivo
                            <option value="1">Sospeso
                            <option value="0">Non tesserato
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-md-3">
                <div class="row">
                    <div class="col-md-12" style="margin-bottom:10px;">
                        <b>Certificato medico</b>
                    </div>
                    <div class="col-12">
                        <select class="form-select filterCertificateScadenza" multiple="multiple">
                            <option value="1">Scaduti
                            <option value="2">In scadenza
                            <option value="3">Non presenti
                            <option value="4">Validi
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-md-3">
                <div class="row">
                    <div class="col-md-12" style="margin-bottom:10px;">
                        <b>Tipologia certificato medico</b>
                    </div>
                    <div class="col-12">
                        <select class="form-select filterCertificateType" multiple="multiple">
                            <option value="N">Non agonistico
                            <option value="A">Agonistico
                        </select>
                    </div>
                </div>
            </div>

        </div>
        <div class="row g-3 mt-1">
            <div class="col-md-2">
                <div class="row">
                    <div class="col-md-12" style="margin-bottom:10px;">
                        <b>Età</b>
                    </div>
                    <div class="col-12">
                        <div class="row">
                            <div class="col-3"><label class="form-check-label ms-2">Da</label></div>
                            <div class="col-9"><input class="form-control txt fromYear" type="number" name="fromYear">
                            </div>
                        </div>
                    </div>
                    <div class="col-12">
                        <div class="row">
                            <div class="col-3"><label class="form-check-label ms-2">A</label></div>
                            <div class="col-9"><input class="form-control txt toYear" type="number" name="toYear"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-md-2">
                <div class="row">
                    <div class="col-md-12" style="margin-bottom:10px;">
                        <b>Anno di nascita</b>
                    </div>
                    <div class="col-12">
                        <div class="row">
                            <div class="col-3"><label class="form-check-label ms-2">Da</label></div>
                            <div class="col-9"><input class="form-control txt fromFromYear" name="fromYearYear"
                                    type="number" name="fromFromYear"></div>
                        </div>
                    </div>
                    <div class="col-12">
                        <div class="row">
                            <div class="col-3"><label class="form-check-label ms-2">A</label></div>
                            <div class="col-9"><input class="form-control txt toToYear" type="number" name="toToYear">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row g-3 mt-2">
            <div class="col-md-12" style="text-align:right">
                <button class="btn--ui_outline light" onclick="reset()">RESET</button>
                <button class="btn--ui" onclick="loadDataTable()">FILTRA</button>
            </div>
        </div>
        <hr size="1">
    </div>

    <section id="resume-table">
        <div class="compare--chart_wrapper d-none"></div>

        <div id="filter">{{$filter}}</div>

        <table class="table tablesaw tableHead tablesaw-stack" id="tablesaw-350" width="100%">
            <thead>
                <tr>
                    <th scope="col">#</th>
                    {{-- <th scope="col">Corso</th> --}}
                    <th scope="col">Cognome</th>
                    <th scope="col">Nome</th>
                    <th scope="col">Certificato</th>
                    <th scope="col">Stato</th>
                    <th scope="col">...</th>
                </tr>
            </thead>
            <tbody id="checkall-target">

            </tbody>
        </table>

    </section>
</div>

@push('scripts')
    <link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
    <style>
        .select2-container--default .select2-selection--single {
            background-color: #E9F0F5;
            border: 0.0625rem solid #DFE5EB;
            font-size: 0.75rem;
        }

        .select2-selection {
            height: 38px !important;
        }

        .select2-selection__rendered {
            padding-top: 3px;
        }

        .select2 {
            width: 100% !important;
        }
    </style>
    <script src="https://code.jquery.com/jquery-2.2.4.min.js"
        integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
@endpush

@push('scripts')
    <link href="/css/datatables.css" rel="stylesheet" />
    <script src="https://code.jquery.com/jquery-2.2.4.min.js"
        integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>


    <link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
    <style>
        .select2-container--default .select2-selection--single {
            background-color: #E9F0F5;
            border: 0.0625rem solid #DFE5EB;
            font-size: 0.75rem;
        }

        .select2-selection {
            height: 38px !important;
        }

        .select2-selection__rendered {
            padding-top: 3px;
        }

        .select2 {
            width: 100% !important;
        }

        .select2-selection--multiple {
            overflow: hidden !important;
            height: auto !important;
        }

        .select2-container {
            box-sizing: border-box;
            display: inline-block;
            margin: 0;
            position: relative;
            vertical-align: middle;
        }

        .select2-container .select2-selection--single {
            box-sizing: border-box;
            cursor: pointer;
            display: block;
            height: 38px;
            user-select: none;
            -webkit-user-select: none;
        }

        .select2-container .select2-selection--single .select2-selection__rendered {
            display: block;
            padding-left: 8px;
            padding-right: 20px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .select2-selection__choice__display {
            color: #000000 !important;
        }
    </style>
    <script src="https://code.jquery.com/jquery-2.2.4.min.js"
        integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
    <script src="/assets/js/datatables.js"></script>
    <script src="https://cdn.datatables.net/buttons/3.0.2/js/buttons.dataTables.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/pdfmake.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/vfs_fonts.js"></script>
@endpush

@push('scripts')
    <script>

        $(document).ready(function () {
            loadDataTable();
        });

        $('.filterCourse').select2({ "language": { "noResults": function () { return "Nessun risultato"; } } });

        $('.filterLevel').select2({ "language": { "noResults": function () { return "Nessun risultato"; } } });

        $('.filterFrequency').select2({ "language": { "noResults": function () { return "Nessun risultato"; } } });

        $('.filterType').select2({ "language": { "noResults": function () { return "Nessun risultato"; } } });

        $('.filterDuration').select2({ "language": { "noResults": function () { return "Nessun risultato"; } } });

        $('.filterDays').select2({ "language": { "noResults": function () { return "Nessun risultato"; } } });

        $('.filterHours').select2({ "language": { "noResults": function () { return "Nessun risultato"; } } });

        $('.filterStatus').select2({ "language": { "noResults": function () { return "Nessun risultato"; } } });

        $('.filterSubscription').select2({ "language": { "noResults": function () { return "Nessun risultato"; } } });

        $('.filterCertificateScadenza').select2({ "language": { "noResults": function () { return "Nessun risultato"; } } });
        $('.filterCertificateType').select2({ "language": { "noResults": function () { return "Nessun risultato"; } } });


        $('.filterYear').select2({ "language": { "noResults": function () { return "Nessun risultato"; } } });
        $('.filterCards').select2({ "language": { "noResults": function () { return "Nessun risultato"; } } });



        /*$(".txt").on('change keydown keypress paste input', function(){
            destroyDataTable();
        });*/

        Livewire.on('load-data-table', () => {
            $('.filterCourse').select2({ "language": { "noResults": function () { return "Nessun risultato"; } } });
            $('.filterLevel').select2({ "language": { "noResults": function () { return "Nessun risultato"; } } });
            $('.filterFrequency').select2({ "language": { "noResults": function () { return "Nessun risultato"; } } });
            $('.filterType').select2({ "language": { "noResults": function () { return "Nessun risultato"; } } });
            $('.filterDuration').select2({ "language": { "noResults": function () { return "Nessun risultato"; } } });
            $('.filterDays').select2({ "language": { "noResults": function () { return "Nessun risultato"; } } });
            $('.filterHours').select2({ "language": { "noResults": function () { return "Nessun risultato"; } } });
            $('.filterStatus').select2({ "language": { "noResults": function () { return "Nessun risultato"; } } });
            $('.filterSubscription').select2({ "language": { "noResults": function () { return "Nessun risultato"; } } });
            $('.filterYear').select2({ "language": { "noResults": function () { return "Nessun risultato"; } } });
            $('.filterCards').select2({ "language": { "noResults": function () { return "Nessun risultato"; } } });
            $('.filterCertificateScadenza').select2({ "language": { "noResults": function () { return "Nessun risultato"; } } });
            $('.filterCertificateType').select2({ "language": { "noResults": function () { return "Nessun risultato"; } } });
            loadDataTable();
        });

        Livewire.on('destroy-data-table', () => {
            $('#tablesaw-350').DataTable().destroy();
        });

        var filterYear = localStorage.getItem("filterYearCourseMember");
        if (filterYear) {
            $('.filterYear').val(filterYear).trigger('change');
        }
        var filterCourse = localStorage.getItem("filterCourseCourseMember");
        if (filterCourse) {
            $('.filterCourse').val(filterCourse).trigger('change');
        }
        var filterLevel = localStorage.getItem("filterLevelCourseMember");
        if (filterLevel) {
            $('.filterLevel').val(filterLevel).trigger('change');
        }
        var filterFrequency = localStorage.getItem("filterFrequencyCourseMember");
        if (filterFrequency) {
            $('.filterFrequency').val(filterFrequency).trigger('change');
        }
        var filterDuration = localStorage.getItem("filterDurationCourseMember");
        if (filterDuration) {
            $('.filterDuration').val(filterDuration).trigger('change');
        }
        var filterType = localStorage.getItem("filterTypeCourseMember");
        if (filterType) {
            $('.filterType').val(filterType).trigger('change');
        }

        var filterDays = localStorage.getItem("filterDaysCourseMember");
        if (filterDays) {
            $('.filterDays').val(filterDays).trigger('change');
        }

        var filterHours = localStorage.getItem("filterHoursCourseMember");
        if (filterHours) {
            $('.filterHours').val(filterHours).trigger('change');
        }

        var filterStatus = localStorage.getItem("filterStatusCourseMember");
        if (filterStatus) {
            $('.filterStatus').val(filterStatus).trigger('change');
        }

        var filterSubscription = localStorage.getItem("filterSubscriptionCourseMember");
        if (filterSubscription) {
            $('.filterSubscription').val(filterSubscription).trigger('change');
        }

        var filterCards = localStorage.getItem("filterCardsCourseMember");
        if (filterCards) {
            $('.filterCards').val(filterCards).trigger('change');
        }

        var filterCertificateScadenza = localStorage.getItem("filterCertificateScadenzaCourseMember");
        if (filterCertificateScadenza) {
            $('.filterCertificateScadenza').val(filterCertificateScadenza).trigger('change');
        }

        var filterCertificateType = localStorage.getItem("filterCertificateTypeCourseMember");
        if (filterCertificateType) {
            $('.filterCertificateType').val(filterCertificateType).trigger('change');
        }

        var fromYear = localStorage.getItem("fromYearCourseMember");
        if (fromYear) {
            $('input[name="fromYear"]').val(fromYear);
        }
        var toYear = localStorage.getItem("toYearCourseMember");
        if (toYear) {
            $('input[name="toYear"]').val(toYear);
        }
        var fromFromYear = localStorage.getItem("fromFromYearCourseMember");
        if (fromFromYear) {
            $('input[name="fromYearYear"]').val(fromFromYear);
        }

        var toYearYear = localStorage.getItem("toYearYearCourseMember");
        if (toYearYear) {
            $('input[name="toToYear"]').val(toYearYear);
        }

            function reset() {
                $('.filterCourse').val(null).trigger("change");
                $('.filterLevel').val(null).trigger("change");
                $('.filterFrequency').val(null).trigger("change");
                $('.filterType').val(null).trigger("change");
                $('.filterDuration').val(null).trigger("change");
                $('.filterDays').val(null).trigger("change");
                $('.filterHours').val(null).trigger("change");
                $('.filterStatus').val(null).trigger("change");
                $('.filterSubscription').val(null).trigger("change");
                $('.filterYear').val(null).trigger("change");
                $('.filterCards').val(null).trigger("change");
                $('.filterCertificateScadenza').val(null).trigger("change");
                $('.filterCertificateType').val(null).trigger("change");
                $('.fromYear').val('');
                $('.toYear').val('');
                $('.fromFromYear').val('');
                $('.toToYear').val('');
                destroyDataTable();
                loadDataTable();
            }

        function destroyDataTable() {
            $('#tablesaw-350').DataTable().destroy();
        }

        var isFilter = false;
        $(document).ready(function () {
            isFilter = Number(localStorage.getItem("isFilter_CourseMember")) ?? false;
            if (isFilter) {
                $(".showFilter").show();
            } else {
                $(".showFilter").hide();
            }
            $(document).on("click", ".showHideFilter", function () {
                if (isFilter) {
                    isFilter = false;
                    $(".showFilter").hide();
                }
                else {
                    isFilter = true;
                    $(".showFilter").show();
                }
                localStorage.setItem("isFilter_CourseMember", Number(isFilter));
            });
        });

        function searchAction() {
            //destroyDataTable();
            //@this.search();
        }

        function loadDataTable() {

            if ($.fn.DataTable.isDataTable('#tablesaw-350')) {
                $('#tablesaw-350').DataTable().destroy();
            }

            var filterCourse = $('.filterCourse').val();
            localStorage.setItem("filterCourseCourseMember", filterCourse);

            var filterLevel = $('.filterLevel').val();
            localStorage.setItem("filterLevelCourseMember", filterLevel);

            var filterDuration = $('.filterDuration').val();
            localStorage.setItem("filterDurationCourseMember", filterDuration);

            var filterFrequency = $('.filterFrequency').val();
            localStorage.setItem("filterFrequencyCourseMember", filterFrequency);

            var filterType = $('.filterType').val();
            localStorage.setItem("filterTypeCourseMember", filterType);

            var filterDays = $('.filterDays').val();
            localStorage.setItem("filterDaysCourseMember", filterDays);

            var filterHours = $('.filterHours').val();
            localStorage.setItem("filterHoursCourseMember", filterHours);

            var filterStatus = $('.filterStatus').val();
            localStorage.setItem("filterStatusCourseMember", filterStatus);

            var filterSubscription = $('.filterSubscription').val();
            localStorage.setItem("filterSubscriptionCourseMember", filterSubscription);

            var filterYear = $('.filterYear').val();
            localStorage.setItem("filterYearCourseMember", filterYear);

            var filterCards = $('.filterCards').val();
            localStorage.setItem("filterCardsCourseMember", filterCards);

            var filterCertificateScadenza = $('.filterCertificateScadenza').val();
            localStorage.setItem("filterCertificateScadenzaCourseMember", filterCertificateScadenza);
            console.log(filterCertificateScadenza);

            var filterCertificateType = $('.filterCertificateType').val();
            localStorage.setItem("filterCertificateTypeCourseMember", filterCertificateType);

            var fromYear = $('.fromYear').val();
            localStorage.setItem("fromYearCourseMember", fromYear);

            var toYear = $('.toYear').val();
            localStorage.setItem("toYearCourseMember", toYear);

            var fromFromYear = $('.fromFromYear').val();
            localStorage.setItem("fromFromYearCourseMember", fromFromYear);

            var toToYear = $('.toToYear').val();
            localStorage.setItem("toYearYearCourseMember", toToYear);

            var filterFromPrevious = '';
            @if($filterFromPrevious != '')
                filterFromPrevious = '&filterFromPrevious={{$filterFromPrevious}}';
            @endif

            let date = new Date();
            let date_export = `${date.getFullYear()}${date.getMonth() + 1}${date.getDate()}_`;


            $('#tablesaw-350').DataTable({
                serverSide: true,
                processing: true,
                stateSave: true,
                ajax: {
                    url: '/get_course_members?filterCourse=' + filterCourse + '&filterDuration=' + filterDuration + '&filterLevel=' + filterLevel + '&filterType=' + filterType + '&filterFrequency=' + filterFrequency + '&filterDays=' + filterDays + '&filterHours=' + filterHours + '&filterStatus=' + filterStatus + '&filterSubscription=' + filterSubscription + '&filterYear=' + filterYear + '&filterCards=' + filterCards + '&filterCertificateScadenza=' + filterCertificateScadenza + '&filterCertificateType=' + filterCertificateType + '&fromYear=' + fromYear + '&toYear=' + toYear + '&fromFromYear=' + fromFromYear + '&toToYear=' + toToYear + filterFromPrevious,
                    /*dataSrc: function (json){
                        if(json.totals){
                            totals = json.totals;
                        }
                        return json.data;
                    }*/
                },
                thead: {
                    'th': { 'background-color': 'blue' }
                },
                columns: [
                    { data: 'column_0' },
                    // { data: 'column_8' },
                    {
                        data: 'column_1',
                        render: function (data, type, row) {
                            var ret = '<a href="/members?member_detail=' + row["column_7"] + '&from=course_member">' + data + '</a>';
                            return ret;
                        }
                    },
                    {
                        data: 'column_2',
                        render: function (data, type, row) {
                            var ret = '<a href="/members?member_detail=' + row["column_7"] + '&from=course_member">' + data + '</a>';
                            return ret;
                        }
                    },
                    /*{ data: 'column_3' },
                    { data: 'column_4' },
                    { data: 'column_9'  },
                    { data: 'column_5' },*/
                    {
                        data: 'column_6',
                        render: function (data, type, row) {


                            var certInfo = data.split("|");
                            var status = certInfo[0];
                            var expireDate = certInfo[1] || "";
                            var html = '<span class="tablesaw-cell-content d-flex align-items-center">';
                            if (status === "0") {
                                html += '<i class="ico--ui check suspended me-2"></i> ';
                                html += 'Scaduto: ' + expireDate;
                            } else if (status === "1") {
                                html += '<i class="ico--ui check due me-2"></i>';
                                html += 'In scadenza: ' + expireDate;
                            } else if (status === "2") {
                                html += '<i class="ico--ui check active me-2"></i>';
                                html += 'Scadenza: ' + expireDate;
                                html += '<span style="float:right"></span>';
                            }else {
                                console.log(status);
                                html += '<i class="ico--ui check absent me-2"></i>';
                                html += 'Non consegnato';
                            }
                            html += '</span>';
                            return html;
                        }
                    },
                    {
                        data: 'column_11',
                        render: function (data, type, row) {
                            var html = '<span class="badge tessera-badge ' + (data == 0 ? 'due' : (data == 1 ? 'active' : 'suspended')) + '">' + (data == 0 ? 'Da pagare' : (data == 1 ? 'Pagato' : 'Sospeso')) + '</span>';
                            return html;
                        }
                    },



                    { data: 'column_10',
                        render: function (data, type, row) {
                            var html = '<a href="/rates?member_id=' + row["column_7"] + '&member_course_id=' + data + '"><b> <i class="fa-solid fa-edit"></i></b></a>';
                            return html;
                        }
                    }],
                layout: {
                    topStart: null,
                    topEnd: null,
                    top1A: {
                        // buttons: [
                        //     {
                        //         extend: 'collection',
                        //         text: 'ESPORTA',
                                buttons: [
                                    {
                                        extend: 'excelHtml5',
                                        text: '<i class="fa-solid fa-file-excel"></i>',
                                        action: newexportaction,
                                        title: date_export + 'Iscritti corsi',
                                        filename: date_export + 'Iscritti corsi',
                                        exportOptions: {
                                            columns: ":not(':last')"
                                        }
                                    },
                                    {
                                        extend: 'pdfHtml5',
                                        text: '<i class="fa-solid fa-file-pdf"></i>',
                                        action: newexportaction,
                                        title: date_export + 'Iscritti corsi',
                                        filename: date_export + 'Iscritti corsi',
                                        exportOptions: {
                                            columns: ":not(':last')"
                                        }
                                    },
                                    {
                                        extend: 'print',
                                        action: newexportaction,
                                        text: '<i class="fa-solid fa-print"></i>',
                                        title: date_export + 'Iscritti corsi',
                                        filename: date_export + 'Iscritti corsi',
                                        exportOptions: {
                                            columns: ":not(':last')"
                                        }
                                    }
                                ],
                        //         dropup: true
                        //     }
                        // ]
                    },
                    top1B: {
                        pageLength: {
                            menu: [[10, 25, 50, 100, 100000], [10, 25, 50, 100, "Tutti"]]
                        }
                    },
                    top1C: 'search',
                    bottomEnd: {
                        paging: {
                            boundaryNumbers: false
                        }
                    }
                },
                order: [[0, 'asc'], [1, 'asc']],
                pagingType: 'first_last_numbers',
                language: {
                    "url": "/assets/js/Italian.json",
                    paginate: {
                        first: '<i class="fa-solid fa-angles-left"></i>',
                        last: '<i class="fa-solid fa-angles-right"></i>',
                    }
                },
                "fnInitComplete": function (oSettings, json) {
                    var html = '&nbsp;<a href="#" class="showHideFilter btn--ui"><i class="fa-solid fa-sliders"></i></a>';
                    $(".dt-search").append(html);
                }
            });

            $('#tablesaw-350 thead tr th').addClass('col');
            $('#tablesaw-350 thead tr th').css("background-color", "#f6f8fa");
            $('#tablesaw-350').on('draw.dt', function () {
                $('[data-bs-toggle="popover"]').popover()
            });

        }

    </script>
@endpush
