<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">@if(!$add && !$update)Corsi @else Inserimento/modifica corso @endif</h2>
        </div>

        @if(!$add && !$update)
            <div class="title--section_addButton"  wire:click="add()" style="cursor: pointer;">
                <div class="btn--ui entrata d-flex justify-items-between">
                    <a href="#" wire:click="add()" style="color:white">Aggiungi</a>
                </div>
            </div>
        @endif

    </header>


    @if(!$add && !$update)


        <a class="btn--ui lightGrey" href="/settings?type=corsi"><i class="fa-solid fa-arrow-left"></i></a><br>

        <div class="row  mt-3" style="margin-bottom:2rem !important;">
            <div class="col-1 mt-4">
                <h4>Anno</h4>
            </div>
            <div class="col-2 mt-4">
                <select class="form-select filterYear" onchange="reload()">
                    <option value="">--Seleziona--
                    @foreach($course_years as $c)
                        @php
                        $selected = '';
                        if ($selectedYear == $c)
                            $selected = 'selected';
                        @endphp
                        <option value="{{$c}}" {{$selected}}>{{$c}}
                    @endforeach
                </select>
            </div>
        </div>

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

            <table class="table tablesaw tableHead tablesaw-stack" id="tablesaw-350" width="100%">
                <thead>
                    <tr>
                        <th  style="text-align:center" scope="col"><input type="checkbox" class="checkAll"></th>
                        <th scope="col">Anno</th>
                        <th scope="col">Tipo</th>
                        <th scope="col">Disciplina</th>
                        <th scope="col">Nome</th>
                        <th scope="col">Livello</th>
                        <th scope="col">Frequenza</th>
                        <th scope="col">N° partecipanti</th>
                        <th scope="col">...</th>
                    </tr>
                </thead>
                <tbody id="checkall-target">
                    @foreach($records as $record)
                        <tr>
                            <td style="text-align:center"><input type="checkbox" class="chkCourse" name="{{$record->id}}"></td>
                            <td>{{$record->year}}</td>
                            <td>{{$record->type == 'standard' ? 'Singolo' : 'Personalizzato'}}</td>
                            <td>{{$record->discipline?->name ?? '-'}}</td>
                            <td>{{$record->name}}</td>
                            <td>{{$record->level->name ?? ""}}</td>
                            <td>{{$record->frequency->name ?? ""}}</td>
                            <td style="padding-right: 50px">{{$record->getCount()}}</td>
                            <td>
                                <button type="button" class="btn" wire:click="edit({{ $record->id }})" data-bs-toggle="popover"  data-bs-trigger="hover focus" data-bs-placement="bottom" data-bs-content="Modifica"><i class="fa-regular fa-pen-to-square"></i></button>
                                <button type="button" class="btn" onclick="confirm('Sei sicuro?') || event.stopImmediatePropagation()" wire:click="delete({{ $record->id }})" data-bs-toggle="popover" data-bs-trigger="hover focus" data-bs-placement="bottom" data-bs-content="Elimina"><i class="fa-regular fa-trash-can"></i></button>
                                <button type="button" class="btn" wire:click="duplicate({{ $record->id }}, false)" data-bs-toggle="popover"  data-bs-trigger="hover focus" data-bs-placement="bottom" data-bs-content="Duplica"><i class="fa-regular fa-copy"></i></button>
                            </td>
                        </tr>
                    @endforeach

                </tbody>
            </table>

        </section>

    @else

        <a class="btn--ui lightGrey" href="/courses?showFilters=1"><i class="fa-solid fa-arrow-left"></i></a><br>

        <div class="container">

            @if (session()->has('error'))
                <div class="alert alert-danger" role="alert">
                    {{ session()->get('error') }}
                </div>
            @endif

            <div class="row">
                <div class="col">

                    <form action="">

                        <div class="row mb-3 ">
                            <div class="col-12 mt-2">
                                <input type="radio" name="chkType" value="standard" wire:model="type">&nbsp;Singolo
                                &nbsp;&nbsp;&nbsp;
                                <input type="radio" name="chkType" value="custom" wire:model="type">&nbsp;Personalizzato
                            </div>

                            <div class="col-6 mt-2">
                                <div class="form--item">
                                    <label for="inputName" class="form-label">Disciplina</label>
                                    <select class="form-select form-select-lg me-1 @error('discipline_id') is-invalid @enderror" wire:model="discipline_id">
                                        <option value="">
                                        @foreach($disciplines as $discipline)
                                            <option value="{{$discipline["id"]}}">{{$discipline["name"]}}
                                        @endforeach
                                    </select>
                                    @error('discipline_id')
                                        <div class="invalid-feedback">{{ $message }}</div>
                                    @enderror
                                </div>
                            </div>

                            <div class="col-6 mt-2">
                                <div class="form--item">
                                    <label for="inputName" class="form-label">Nome</label>
                                    <input class="form-control js-keyupTitle @error('name') is-invalid @enderror" type="text" id="name" placeholder="Nome" wire:model="name">
                                    @error('name')
                                        <div class="invalid-feedback">{{ $message }}</div>
                                    @enderror
                                </div>
                            </div>
                            @if(false)
                                {{-- <div class="col-6 mt-2">
                                    <div class="form--item">
                                        <label for="inputName" class="form-label">Tipologia</label>
                                        <select class="form-select form-select-lg me-1 @error('course_type_id') is-invalid @enderror" wire:model="course_type_id">
                                            <option value="">
                                            @foreach($course_types as $c)
                                                <option value="{{$c["id"]}}">{{$c["name"]}}</option>
                                            @endforeach
                                        </select>
                                    </div>
                                </div> --}}
                                <div class="col-6 mt-2">
                                    <div class="form--item">
                                        <label for="inputName" class="form-label">Durata</label>
                                        <select class="form-select form-select-lg me-1 @error('course_duration_id') is-invalid @enderror" wire:model="course_duration_id">
                                            <option value="">
                                            @foreach($course_durations as $c)
                                                <option value="{{$c["id"]}}">{{$c["name"]}}</option>
                                            @endforeach
                                        </select>
                                    </div>
                                </div>
                            @endif
                            <div class="col-6 mt-2">
                                <div class="form--item">
                                    <label for="inputName" class="form-label">Frequenza</label>
                                    <select class="form-select form-select-lg me-1 @error('course_frequency_id') is-invalid @enderror" wire:model="course_frequency_id">
                                        <option value="">
                                        @foreach($course_frequencies as $c)
                                            <option value="{{$c["id"]}}">{{$c["name"]}}</option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>
                            <div class="col-6 mt-2">
                                <div class="form--item">
                                    <label for="inputName" class="form-label">Livello</label>
                                    <select class="form-select form-select-lg me-1 @error('course_level_id') is-invalid @enderror" wire:model="course_level_id">
                                        <option value="">
                                        @foreach($course_levels as $c)
                                            <option value="{{$c["id"]}}">{{$c["name"]}}</option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>
                            <div class="col-3 mt-2">
                                <div class="form--item">
                                    <label for="inputName" class="form-label">Data inizio</label>
                                    <input class="form-control @error('date_from') is-invalid @enderror" type="date" placeholder="Data inizio" wire:model="date_from">
                                </div>
                            </div>
                            <div class="col-3 mt-2">
                                <div class="form--item">
                                    <label for="inputName" class="form-label">Data fine</label>
                                    <input class="form-control @error('date_to') is-invalid @enderror" type="date" placeholder="Data fine" wire:model="date_to">
                                </div>
                            </div>
                            @if(false)
                                <div class="col-6 mt-2">
                                    <div class="form--item">
                                        <label for="inputName" class="form-label">Prezzo mensile</label>
                                        <input class="form-control js-keyupTitle @error('price') is-invalid @enderror" type="text" id="price" onkeyup="onlyNumberAmount(this)" placeholder="€ 0,00" wire:model="price">
                                        @error('price')
                                            <div class="invalid-feedback">{{ $message }}</div>
                                        @enderror
                                    </div>
                                </div>
                                <div class="col-6 mt-2">
                                    <div class="form--item">
                                        <label for="inputName" class="form-label">Prezzo iscrizione</label>
                                        <input class="form-control js-keyupTitle @error('subscription_price') is-invalid @enderror" type="text" id="subscription_price" onkeyup="onlyNumberAmount(this)" placeholder="€ 0,00" wire:model="subscription_price">
                                        @error('subscription_price')
                                            <div class="invalid-feedback">{{ $message }}</div>
                                        @enderror
                                    </div>
                                </div>
                                <div class="col-6 mt-2">
                                    <div class="form--item">
                                        <label for="inputName" class="form-label">Causale</label>
                                        <livewire:causals :type="$typeIN" :idx="0" :show_hidden=0 :causal_id="$causal_id" :wire:key="0" />
                                        @error('causal_id')
                                            <span style="argin-top: 0.25rem; font-size: 0.875em; color: var(--bs-form-invalid-color);">{{ $message }}</span>
                                        @enderror
                                    </div>
                                </div>
                                <div class="col-6 mt-2">
                                    <div class="form--item">
                                        <label for="inputName" class="form-label">Causale iscrizione</label>
                                        <livewire:causals :type="$typeIN" :idx="0" :show_hidden=0 :causal_id="$sub_causal_id" :wire:key="0" :emit="$setSubscriptionCausal" />
                                        @error('sub_causal_id')
                                            <span style="argin-top: 0.25rem; font-size: 0.875em; color: var(--bs-form-invalid-color);">{{ $message }}</span>
                                        @enderror
                                    </div>
                                </div>
                            @endif

                            {{-- <div class="col-6 mt-2">
                                <div class="form--item">
                                    <label for="inputName" class="form-label">Causale</label>
                                    <livewire:causals :type="$typeIN" :idx="0" :show_hidden=0 :causal_id="$causal_id" :wire:key="0" />
                                    @error('causal_id')
                                        <span style="argin-top: 0.25rem; font-size: 0.875em; color: var(--bs-form-invalid-color);">{{ $message }}</span>
                                    @enderror
                                </div>
                            </div>
                            <div class="col-6 mt-2">
                                <div class="form--item">
                                    <label for="inputName" class="form-label">Causale iscrizione</label>
                                    <livewire:causals :type="$typeIN" :idx="0" :show_hidden=0 :causal_id="$sub_causal_id" :wire:key="0" :emit="$setSubscriptionCausal" />
                                    @error('sub_causal_id')
                                        <span style="argin-top: 0.25rem; font-size: 0.875em; color: var(--bs-form-invalid-color);">{{ $message }}</span>
                                    @enderror
                                </div>
                            </div> --}}

                            <div class="col-6 mt-2">
                                <div class="form--item">
                                    <label for="inputName" class="form-label">N° partecipanti</label>
                                    <input class="form-control js-keyupTitle @error('max_members') is-invalid @enderror" type="text" id="max_members" placeholder="Numero massimo partecipanti" wire:model="max_members">
                                    @error('max_members')
                                        <div class="invalid-feedback">{{ $message }}</div>
                                    @enderror
                                </div>
                            </div>

                            <div class="col-6 mt-2">
                                <div class="form--item">
                                    <label for="inputName" class="form-label">Istruttore</label>
                                    <select class="form-select form-select-lg" wire:model="instructor_id">
                                        <option value="">
                                        @foreach($instructors as $ins)
                                            <option value="{{$ins["id"]}}">{{$ins["name"]}} {{$ins["cognome"]}}</option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>

                            <div class="col-6 mt-2">
                                <div class="form--item">
                                    <label for="inputName" class="form-label">Gruppo di interesse</label>
                                    <select class="form-select form-select-lg me-1 @error('category_id') is-invalid @enderror" wire:model="category_id">
                                        <option value="">
                                        @foreach($categories as $category)
                                            <option value="{{$category["id"]}}">{{str_repeat('  ', $category["indentation"])}}{{$category["name"]}}
                                        @endforeach
                                    </select>
                                </div>
                            </div>

                            <div class="col-6 mt-2">
                                <div class="form--item">
                                    <label for="inputName" class="form-label">Anno</label>
                                    <select class="form-control @error('year') is-invalid @enderror" wire:model="year">
                                        <option value=""></option>
                                        @for($i=2024; $i<=date("Y") + 1; $i++)
                                            <option value="{{$i . "-" . $i + 1}}">{{$i . "/" . $i + 1}}
                                        @endfor
                                    </select>
                                </div>
                            </div>

                            <div class="col-6 mt-2">
                                <div class="form--item">
                                    <label for="inputName" class="form-label">Prezzo iscrizione</label>
                                    <input class="form-control js-keyupTitle @error('subscription_price') is-invalid @enderror" type="text" id="subscription_price" onkeyup="onlyNumberAmount(this)" placeholder="€ 0,00" wire:model="subscription_price">
                                    @error('subscription_price')
                                        <div class="invalid-feedback">{{ $message }}</div>
                                    @enderror
                                </div>
                            </div>

                            <div class="col-6 mt-2">
                                @foreach($prices as $idP => $p)
                                    <div class="row mt-2 ">
                                        <div class="col-6">
                                            <label for="abb" class="form-label">Pagamento</label>
                                            <select class="form-control" wire:model="prices.{{$idP}}.course_subscription_id">
                                                <option value=""></option>
                                                @foreach($course_subscriptions as $s)
                                                    <option value="{{$s["id"]}}">{{$s["name"]}}
                                                @endforeach
                                            </select>
                                        </div>
                                        <div class="col-4">
                                            <label for="price" class="form-label">Prezzo</label>
                                            <input class="form-control " type="text" onkeyup="onlyNumberAmount(this)" placeholder="€ 0,00" wire:model="prices.{{$idP}}.price">
                                        </div>
                                        <div class="col-2">
                                            @if($idP == 0)
                                                <br><button class="btn--ui primary add--daye" wire:click.prevent="addPrice()"><i class="fa-solid fa-plus"></i></button>
                                            @endif
                                            @if($idP > 0)
                                                <br><button class="btn--ui primary add--daye" wire:click.prevent="delPrice({{$idP}})"><i class="fa-solid fa-minus"></i></button>
                                            @endif
                                        </div>
                                        <div class="col-12">
                                            <span style="color:red">{{$msgPrices}}</span>
                                        </div>
                                    </div>
                                @endforeach
                            </div>
                            
                            @if($type == 'standard')

                                @foreach($when as $idW => $w)
                                    @if ($idW > 0)
                                    <div class="col-6"></div>
                                    @endif
                                    <div class="col-6 mt-4">
                                        <div class="day durata--corso d-flex">
                                            <label for="" class="form-label">Giorno</label>
                                            <div class="durata--corso_days mb-3">
                                                <a class="{{in_array('lun', $when[$idW]["day"]) ? 'selected' : 'notSelected'}}" wire:click="setDay({{$idW}}, 'lun')">Lun</a>
                                                <a class="{{in_array('mar', $when[$idW]["day"]) ? 'selected' : 'notSelected'}}" wire:click="setDay({{$idW}}, 'mar')">Mar</a>
                                                <a class="{{in_array('mer', $when[$idW]["day"]) ? 'selected' : 'notSelected'}}" wire:click="setDay({{$idW}}, 'mer')">Mer</a>
                                                <a class="{{in_array('gio', $when[$idW]["day"]) ? 'selected' : 'notSelected'}}" wire:click="setDay({{$idW}}, 'gio')">Gio</a>
                                                <a class="{{in_array('ven', $when[$idW]["day"]) ? 'selected' : 'notSelected'}}" wire:click="setDay({{$idW}}, 'ven')">Ven</a>
                                                <a class="{{in_array('sab', $when[$idW]["day"]) ? 'selected' : 'notSelected'}}" wire:click="setDay({{$idW}}, 'sab')">Sab</a>
                                                <a class="{{in_array('dom', $when[$idW]["day"]) ? 'selected' : 'notSelected'}}" wire:click="setDay({{$idW}}, 'dom')">Dom</a>
                                            </div>

                                            <div class="durata--corso_select">
                                                <div class="from--h me-3">
                                                    <label for="" class="form-label">Dalle</label>
                                                    <select class="form-select" wire:model="when.{{$idW}}.from">
                                                        <option value="">--Seleziona--
                                                        @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 class="to--h">
                                                    <label for="" class="form-label">Alle</label>
                                                    <select class="form-select" wire:model="when.{{$idW}}.to">
                                                        <option value="">--Seleziona--
                                                        @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>

                                            <button class="btn--ui primary remove--day position-absolute" wire:click.prevent="delRow({{$idW}})"><i class="fa-solid fa-minus"></i></button>
                                            <button class="btn--ui primary add--day position-absolute" wire:click.prevent="addRow()"><i class="fa-solid fa-plus"></i></button>
                                        </div>
                                        <div class="col-12">
                                            <span style="color:red">{{$msgWhen}}</span>
                                        </div>
                                    </div>

                                @endforeach
                            
                            @endif

                            

                        </div>
                        <div class="row">
                            <div class="col-6">
                                <div class="form--item">
                                    <label for="enabled" class="form-label">Abilitato</label>
                                    <input class="form-check-input form-control" style="width:22px; height:22px;" type="checkbox" id="enabled" wire:model="enabled">
                                </div>
                            </div>
                        </div>

                        <div class="form--item mt-4">
                            <button type="button" class="btn--ui lightGrey" onclick="annulla()">Annulla</button>
                            @if($add)
                                <button type="submit" class="btn--ui" wire:click.prevent="store()">Salva</button>
                            @endif
                            @if($update)
                                <button type="submit" class="btn--ui" wire:click.prevent="update()">Salva</button>
                            @endif
                        </div>

                    </form>
                </div>
            </div>
        </div>

    @endif
</div>

@push('scripts')
    <link href="/css/datatables.css" rel="stylesheet" />
    <style>
        a.notSelected
        {
            display: flex;
            margin-right:10px;
            float:left;
            height: 2.5rem !important;
            width:50px;
            align-items: center;
            justify-content: center;
            color: var(--color-blu);
            background-color: #d3dce1 !important;
            padding: 0 1.25rem;
            font-size: 0.875rem;
            font-family: greycliff-cf, sans-serif;
            border-radius: 1.875rem !important;
            -webkit-border-radius: 1.875rem !important;
            -moz-border-radius: 1.875rem !important;
            -webkit-transition: all 0.3s ease-in-out;
            -moz-transition: all 0.3s ease-in-out;
            -o-transition: all 0.3s ease-in-out;
            transition: all 0.3s ease-in-out;
            border: none;
        }
        a.selected
        {
            display: flex;
            margin-right:10px;
            float:left;
            height: 2.5rem !important;
            width:50px;
            align-items: center;
            justify-content: center;
            color: #fff;
            background-color: var(--color-blu) !important;
            padding: 0 1.25rem;
            font-size: 0.875rem;
            font-family: greycliff-cf, sans-serif;
            border-radius: 1.875rem !important;
            -webkit-border-radius: 1.875rem !important;
            -moz-border-radius: 1.875rem !important;
            -webkit-transition: all 0.3s ease-in-out;
            -moz-transition: all 0.3s ease-in-out;
            -o-transition: all 0.3s ease-in-out;
            transition: all 0.3s ease-in-out;
            border: none;
        }
        div.day
        {
            margin-top:20px;
            color: var(--color-blu);
            background-color: #ffffff !important;
            padding: 20px;
            border-radius: 1.875rem !important;
            -webkit-border-radius: 1.875rem !important;
            -moz-border-radius: 1.875rem !important;
            -webkit-transition: all 0.3s ease-in-out;
            -moz-transition: all 0.3s ease-in-out;
            -o-transition: all 0.3s ease-in-out;
            transition: all 0.3s ease-in-out;
            border: 2px solid #d3dce1;
        }
    </style>
    <script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></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>

        function onlyNumberAmount(input) {
            let v = input.value.replace(/\D+/g, '');
            if (v.length > 14) v = v.slice(0, 14);
            input.value = "€ " + v.replace(/(\d)(\d\d)$/, "$1,$2").replace(/(^\d{1,3}|\d{3})(?=(?:\d{3})+(?:,|$))/g, '$1.');
        }

        var isEdit = false;

        Livewire.on('setEdit', (x) =>
        {
            isEdit = x;
            console.log(isEdit);
        });

        function annulla()
        {
            window.onbeforeunload = null;
            document.location.href = '/courses';
        }

        window.onbeforeunload = function(){
            if (isEdit)
                return 'Cambiando pagina le eventuali modifiche andranno perse';

        };

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

        Livewire.on('load-data-table', () => {
            loadDataTable();
        });

        function reload()
        {
            console.log($(".filterYear").val());
            window.location.href = '/courses?year=' + $(".filterYear").val();
        }

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

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

            $('#tablesaw-350').DataTable({
                processing: true,
                stateSave: true,
                thead: {
                'th': {'background-color': 'blue'}
                },
                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 + 'Corsi',
                                        filename: date_export + 'Corsi',
                                        exportOptions: {
                                            columns: ":not(':last')"
                                        }
                                    },
                                    {
                                        extend: 'pdfHtml5',
                                        text: '<i class="fa-solid fa-file-pdf"></i>',
                                        action: newexportaction,
                                        title: date_export + 'Corsi',
                                        filename: date_export + 'Corsi',
                                        exportOptions: {
                                            columns: ":not(':last')"
                                        }
                                    },
                                    {
                                        extend: 'print',
                                        action: newexportaction,
                                        text: '<i class="fa-solid fa-print"></i>',
                                        title: date_export + 'Corsi',
                                        filename: date_export + '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
                        }
                    }
                },
                "columnDefs": [ {
                "targets": 0,
                "orderable": false
                } ],
                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="addData btn--ui"><i class="fa-solid fa-plus"></i></a>';
                    $(".dt-search").append(html);
                    html = '&nbsp;<a href="#" class="duplicateData btn--ui" style="display:none"><i class="fa-solid fa-copy fa-lg" style="height:5px;"></i></a>';
                    $(".dt-buttons").after(html);
                }
            });
            $('#tablesaw-350 thead tr th').addClass('col');
            $('#tablesaw-350 thead tr th').css("background-color", "#f6f8fa");

            var courses = [];
            $(".chkCourse").click(function(){
                var id = $(this).attr('name');
                if(!courses.includes(id)){
                    courses.push(id);
                }else{
                    courses.splice(courses.indexOf(id), 1);  //deleting
                }
                if (courses.length > 0)
                    $(".duplicateData").show();
                else
                    $(".duplicateData").hide();
                console.log(courses);
            });

            $(document).ready(function() {
                $(document).on("click",".addData",function() {
                    $(".title--section_addButton").trigger("click");
                });
                $(document).on("click",".duplicateData",function() {
                    @this.duplicateMultiple(courses);
                });
            } );

            var all = false;
            $(".checkAll").click(function(){
                all = !all;
                courses = [];
                $('.chkCourse').each(function(){
                    $(this).prop('checked', all);
                    if (all)
                        courses.push($(this).attr('name'));
                });
                if (courses.length > 0)
                    $(".duplicateData").show();
                else
                    $(".duplicateData").hide();
                console.log(courses);
            });

        }

    </script>

@endpush
