<div>
    @if($showDetail)
        <div class="col card--ui" id="card--dashboard">
            <a style="margin-top:20px" class="btn--ui lightGrey" href="/{{$from != '' ? ($from . '?showFilters=1') : 'members'}}"><i class="fa-solid fa-arrow-left"></i></a><br><br>
            <div class="col col-lg-12" style="margin-bottom:100px;">
                <div class="user--profile d-lg-flex" style="margin-top:20px !important">
                    <div class="user--profile_card d-flex justify-content-between flex-column w-100 w-lg-auto mb-3 mb-lg-0">
                        <div class="user--details">
                            <header>
                                <div class="avatar--wrapper d-flex align-items-center justify-content-between w-50">
                                    <figure class="m-0 avatar--wrapper_img">
                                        @if ($currentMember->image != '')
                                            @php
                                                $fileService = app(App\Services\MemberFileService::class);
                                                $imageUrl = $fileService->getFileUrl($currentMember->image);
                                            @endphp
                                            @if($imageUrl)
                                                <img src="{{ $imageUrl }}" style="max-width:200px" alt="Profile Image">
                                            @else
                                                <div style="width: 200px; height: 150px; background: #f0f0f0; display: flex; align-items: center; justify-content: center;">
                                                    <span style="color: #999;">Image not available</span>
                                                </div>
                                            @endif
                                        @endif
                                    </figure>
                                </div>
                            </header>
                            <article>
                                <header class="title d-flex align-items-center mb-3 gap-4"><i class="fa-solid fa-wallet"></i><span>Borsellino</span></header>
                                <div class="credito d-flex align-items-center justify-content-between">
                                    <div class="credito_title">
                                        <span>Borsellino MAD: <br></span><span class="value">{{formatPrice($currentMember->getMoney())}}</span>
                                    </div>
                                    <a href="/in?new=1&memberId={{$currentMember->id}}&causalId={{$causalId > 0 ? $causalId : ''}}" class="btn--ui lightGrey" style="width:100px">ricarica</a>

                                </div>
                                <div class="credito d-flex align-items-center justify-content-between">
                                    <br><br><button type="button" class="btn--ui primary" data-bs-toggle="modal" data-bs-target="#userModal"  style="width:100px">Modifica</button>
                                </div>
                            </article>
                            <article>
                                <header class="title d-flex align-items-center mb-3 gap-4"><i class="fa-solid fa-file-lines"></i><span>Certificato</span></header>
                                @if(sizeof($currentMember->certificates) > 0)
                                    @php
                                    $cert = $currentMember->certificates[0];

                                    $fileService = app(App\Services\MemberFileService::class);
                                    $certificateUrl = "#";
                                    if($cert->filename != '') {
                                        $certificateUrl = $fileService->getFileUrl($cert->filename);
                                    }
                                    @endphp
                                    
                                    <div class="resume--wrapper d-flex align-items-start justify-content-between mb-2">
                                        <div class="resume--info resume-certificato d-flex align-items-start">
                                            <div class="title--tessera_added">
                                                <h4>{{$cert->type == 'A' ? 'Agonistico' : 'Non agonistico'}}</h4>
                                                <span class="title-detail">Scadenza: <span class="title-detail_date">{{$cert->expire_date ? date("d/m/Y", strtotime($cert->expire_date)) : ''}}</span></span></small>
                                                @if($certificateUrl != "#")
                                                    <small><small><a href="{{$certificateUrl}}" target="_blank" class="member-file-url">Visualizza</a></small></small>
                                                @endif
                                            </div>
                                        </div>
                                        @if($cert->expire_date . " 23:59:59" < date("Y-m-d"))
                                            <span class="badge tessera-badge suspended">scaduto</span>
                                        @endif
                                        @if($cert->expire_date . " 23:59:59" >= date("Y-m-d") && $cert->expire_date < date("Y-m-d", strtotime("+1 month")))
                                            <span class="badge tessera-badge due">in scadenza</span>
                                        @endif
                                        @if($cert->expire_date . " 23:59:59" >= date("Y-m-d", strtotime("+1 month")))
                                            <span class="badge tessera-badge active">valido</span>
                                        @endif
                                    </div>
                                @endif
                            </article>
                            <article>
                                <header class="title d-flex align-items-center mb-3 gap-4"><i class="fa-solid fa-address-card"></i><span>Tesseramento</span></header>
                                @if(sizeof($currentMember->cards) > 0)
                                    @foreach($currentMember->cards as $card)
                                        @php
                                        $active = 'active';
                                        if ($card->expire_date != '' && $card->expire_date < date("Y-m-d  23:59:59"))
                                        {
                                            $active = 'suspended';
                                        }
                                        @endphp
                                        @if($active != 'suspended')
                                            {{-- <ul class="course-list m-0 p-0">
                                                <li>
                                                    <span class="course_name">
                                                        {{$card->card->name}}<br>
                                                        Scadenza: <span class="title-detail_date">{{$card->expire_date ? date("d/m/Y", strtotime($card->expire_date)) : ''}}
                                                        </span>
                                                    </span>
                                                    <span style="float:right">
                                                        <span class="badge tessera-badge {{$active}}">{{$active == 'active' ? 'ATTIVA' : 'SCADUTA'}}
                                                    </span>
                                                </li>
                                            </ul> --}}
                                    
                                            <div class="resume--wrapper d-flex align-items-start justify-content-between mb-2">
                                                <div class="resume--info resume-tessera d-flex align-items-start">
                                                    <div class="title--tessera_added">
                                                        <h4>{{$card->card->name}}</h4>
                                                        <span class="title-detail">Scadenza: <span class="title-detail_date">{{$card->expire_date ? date("d/m/Y", strtotime($card->expire_date)) : ''}}</span></span></small>
                                                        @if($card->discipline_1)
                                                        </br>
                                                            <span class="title-detail">Disciplina : <b>{{$card->discipline_1->name}}</b></span>
                                                        @endif
                                                        @if($card->discipline_2)
                                                        </br>
                                                            <span class="title-detail">Disciplina : <b>{{$card->discipline_2->name}}</b></span>
                                                        @endif
                                                        @if($card->discipline_3)
                                                        </br>
                                                            <span class="title-detail">Disciplina : <b>{{$card->discipline_3->name}}</b></span>
                                                        @endif
                                                    </div>
                                                </div>
                                                <span class="badge tessera-badge {{$active}}">{{$active == 'active' ? 'ATTIVA' : 'SCADUTA'}}</span>
                                            </div>
                                        @endif
                                    @endforeach
                                @endif
                            </article>
                        </div>
                    </div>
                    <div class="user--profile_resume">
                        <header class="d-flex align-item-center ">
                            <div class="user_name me-4">
                                <span class="name">{{$currentMember->first_name}} {{$currentMember->last_name}}</span>
                                <span class="badge tessera-badge {{$currentStatus["status"] > 0 ? ($currentStatus["status"] == 2 ? 'active' : 'due') : 'suspended'}}">{{$currentStatus["status"] > 0 ? ($currentStatus["status"] == 2 ? 'Tesserato' : 'Sospeso') : 'Non tesserato'}}</span>
                            </div>
                            <button class="btn--ui lightGrey" wire:click="edit({{ $currentMember->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>
                        </header>
                        <ul class="user-address mb-4 p-0">
                            <li><i class="fa-solid fa-phone"></i><span>Tel. {{ $currentMember->phone }}</span></li>
                            <li><i class="fa-solid fa-calendar"></i><span>Nato il {{ $currentMember->birth_date ? date("d/m/Y", strtotime($currentMember->birth_date)) : '' }}&nbsp;({{$currentMember->getAge()}} anni)</span></li>
                            <li><i class="fa-solid fa-envelope"></i><span><a href="mailto:{{ $currentMember->email }}" target="_blank">{{ $currentMember->email }}</a></span></li>
                        </ul>
                        <ul class="user-residence p-0">
                            <li><i class="fa-solid fa-building"></i>
                                <span>
                                    @if($currentMember->city_id > 0)
                                        {{$this->getCity($currentMember->city_id)}}
                                        @if($currentMember->province_id > 0)
                                            ( {{$this->getProvince($currentMember->province_id)}} ) -
                                        @endif
                                    @endif
                                    {{ $currentMember->zip_code }}<br>
                                    {{ $currentMember->address }}
                                </span>
                            </li>
                        </ul>
                        <div class="resume--tab_info gruppi">
                            <h2 class="title d-flex align-items-center mb-3 gap-4"><i class="fa-solid fa-users"></i>Gruppi di interesse</h2>
                            <div class="resume--info d-flex align-items-start row">

                                @foreach($currentMember->categories as $member_category)
                                    <div class="align-items-baseline col-md-3 d-flex gap-2 mb-3">
                                        {{-- <i class="fa-solid fa-users"></i> --}}
                                        <div class="title" style="margin-right:20px">
                                            <h4>{{$member_category->category->getTree()}}</h4>
                                        </div>
                                    </div>
                                @endforeach

                            </div>
                        </div>
                        <div class="resume--tab_info corsi">
                            <h2 class="title d-flex align-items-center mb-3 gap-4"><i class="fa-solid fa-chalkboard"></i>Corsi e Abbonamenti</h2>
                            @foreach($currentMember->subscriptions as $member_subscription)
                                @php
                                    $course_year = date('Y', strtotime($member_subscription->date_from));
                                    $current_year = date('Y');
                                    $course_month = date('m', strtotime($member_subscription->date_from));
                                    $current_month = date('m');
                                @endphp
                                @if (
                                    ($course_year == (date('Y') + 1) && $course_month <=8) ||
                                    ($course_year == date('Y') && $course_month >= 9)
                                )
                                    <div class="resume--info resume-corso d-flex align-items-center">
                                        <div class="row">
                                            <div class="row">
                                                <strong>{{$member_subscription->subscription->name}}</strong>
                                            </div>
                                            <div class="row">
                                                <span class="title-detail">
                                                    {{date('d/m/Y', strtotime($member_subscription->date_from))}} - {{date('d/m/Y', strtotime($member_subscription->date_to))}}
                                                    {{-- @if($member_subscription->notes != '')
                                                        <b>Note: </b>
                                                        {{$member_subscription->notes}}
                                                    @endif --}}
                                                </span>
                                            </div>
                                        </div>
                                    </div>
                                @endif
                            @endforeach
                            @foreach($currentMember->courses as $member_course)
                                @php
                                    $course_year = date('Y', strtotime($member_course->date_from));
                                    $current_year = date('Y');
                                    $course_month = date('m', strtotime($member_course->date_from));
                                    $current_month = date('m');
                                @endphp
                                @if (
                                    ($course_year == (date('Y') + 1) && $course_month <=8) ||
                                    ($course_year == date('Y') && $course_month >= 9)
                                )
                                    <div class="resume--info resume-corso d-flex align-items-center">
                                        <div class="row">
                                            <div class="row">
                                                <strong>{{$member_course->course->getTree()}}</strong>
                                            </div>
                                            <div class="row">
                                                <span class="title-detail">
                                                    {{$member_course->course->level->name ?? ""}}<br>
                                                    {{$member_course->course->frequency->name ?? ""}}
                                                </span>
                                            </div>
                                            <div class="row">
                                                <span class="title-detail">
                                                    @php
                                                        $ok = false;
                                                    @endphp
                                                    @foreach(json_decode($member_course->when) as $xx => $x)
                                                        @if($xx > 0)
                                                            <br>
                                                        @endif
                                                        @foreach($x->day as $zz => $d)
                                                            {{$zz > 0 ? '-' : ''}}{{$d}}
                                                        @endforeach
                                                        @if($x->from != '' && $x->to != '')
                                                            h {{$x->from}} - {{$x->to}}
                                                        @endif
                                                        @php
                                                            $ok = $x->from != '';
                                                        @endphp
                                                    @endforeach
                                                    @if(!$ok && $member_course->course->when != '')
                                                        @foreach(json_decode($member_course->course->when) as $xx => $x)
                                                            @php
                                                                $ok = true;
                                                            @endphp
                                                            @if($xx > 0)
                                                                <br>
                                                            @endif
                                                            @foreach($x->day as $zz => $d)
                                                                {{$zz > 0 ? '-' : ''}}{{$d}}
                                                            @endforeach
                                                            @if($x->from != '')
                                                                h {{$x->from}} - {{$x->to}}
                                                            @endif
                                                        @endforeach
                                                    @endif
                                                </span>
                                            </div>
                                        </div>
                                    </div>
                                @endif
                            @endforeach
                        </div>
                    </div>
                </div>
                <div class="service--button d-md-flex align-items-center " style="margin-bottom:30px">
                    <button class="btn--ui lightGrey" onclick="annulla()" style="margin-right:10px">annulla</button>
                    <div class="payment_btn">
                        <a href="/in?new=1&memberId={{$currentMember->id}}" class="btn--ui primary">NUOVA ENTRATA</a>
                    </div>
                </div>
            </div>
        </div>
    @else
        <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" style="display:none !important">
                <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)Utenti @else Inserimento/modifica utente @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="#" style="color:white">Aggiungi</a>
                        </div>
                    </div>
                @endif
            </header>
            @if(!$add && !$update)
                <section id="subheader" class="d-flex align-items-center justify-content-between">
                    @if(false)
                    <form action="" class="search--form d-flex align-items-center">
                        <div class="input-group mb-3">
                            <input type="text" class="form-control" placeholder="Cerca utente" aria-label="cerca utent" aria-describedby="button-addon2" wire:model="search">
                            @if($showReset)
                                <button class="btn--ui" type="button" id="button-addon2" onclick="reset()"><i class="ico--ui search"></i>Reset</button>
                            @else
                                <button class="btn--ui" type="button" id="button-addon2" wire:click="search()"><i class="ico--ui search"></i>Cerca</button>
                            @endif
                        </div>
                    </form>
                    @endif
                </section>

                <div class="showFilter" style="display:none">
                    <hr size="1">
                    <div class="row g-3">
                        <div class="col-md-3">
                            <div class="row">
                                <div class="col-md-12" style="margin-bottom:10px;">
                                    <b>Età</b>
                                </div>
                                <div class="col-12">
                                    <div class="row mb-2">
                                        <div class="col-3"><label class="form-check-label ms-2" >Da</label></div>
                                        <div class="col-9"><input class="form-control " type="number" name="txtFromYear"></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 " type="number"  name="txtToYear"></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <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 name="filterCards" class="form-select filterCards">
                                        <option value="">Tutte
                                        @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 name="filterStatus" 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>Gruppo di interesse</b>
                                </div>
                                <div class="col-12">
                                    <select name="filterCategories" class="form-select filterCategories" multiple="multiple">
                                        <option value="">Tutte</option>
                                        @foreach($categories as $category)
                                            <option value="{{$category["id"]}}">
                                                {!! str_repeat('&bull; ', $category["indentation"] ?? 0) !!}{{$category["name"]}}
                                            </option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-3">
                            <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 mb-2">
                                        <div class="col-3"><label class="form-check-label ms-2" >Da</label></div>
                                        <div class="col-9"><input class="form-control " type="number" name="txtFromYearYear"></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 " type="number"  name="txtToYearYear"></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-3">
                            <div class="row">
                                <div class="col-md-12" style="margin-bottom:10px;">
                                    <b>Scadenza certificato medico</b>
                                </div>
                                <div class="col-12">
                                    <select name="filterScadenza" class="form-select filterScadenza" multiple="multiple">
                                        <option value="1">Scaduti
                                        <option value="2">In scadenza
                                        <option value="3">Non consegnato
                                        <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 name="filterCertificateType" class="form-select filterCertificateType" multiple="multiple">
                                        <option value="">Tutti
                                        <option value="N">Non agonistico
                                        <option value="A">Agonistico
                                    </select>
                                </div>
                            </div>
                        </div>

                    </div>
                    <div class="row g-3">
                        <div class="col-md-12" style="text-align:right">
                            <button class="btn--ui lightGrey" onclick="reset()" onclick="destroyDataTable()">Reset</button>
                            <button class="btn--ui" onclick="loadDataTable()">FILTRA</button>
                        </div>
                    </div>
                    <hr size="1">
                </div>
                <section id="anagrafiche--utenti">
                    <div class="compare--chart_wrapper d-none"></div>
                    <table class="table tablesaw tableHead tablesaw-stack table--lista_utenti tableHead" width="100%" id="tablesaw-350" width="100%">
                        <thead>
                            <tr>
                                <th scope="col" style="text-align: center">Cognome</th>
                                <th scope="col">Nome</th>
                                <th scope="col">Telefono</th>
                                <th scope="col" style="text-align: center">Età</th>
                                <th scope="col" style="text-align: center">Anno</th>
                                <th scope="col">Tesseramento</th>
                                <th scope="col">Certificato</th>
                                <th scope="col">...</th>
                            </tr>
                        </thead>
                        <tbody id="checkall-target">
                            @if(false)
                                @foreach($records as $idx => $record)
                                    <tr>
                                        <td> <label><input class="table-check" type="checkbox" wire:model="multipleIds" value="{{$record->id}}"><span class="sr-only d-inline-block d-lg-none ms-2 mobile-row-selector"> Seleziona riga</span></label></td>
                                        <td>{{ ($idx + 1) }}</td>
                                        <td>ID{{str_pad($record->id, 5, "0", STR_PAD_LEFT)}}</td>
                                        <td><a href="#" wire:click="showDetail({{$record->id}})">{{$record->last_name}}</a></td>
                                        <td><a href="#" wire:click="showDetail({{$record->id}})">{{$record->first_name}}</a></td>
                                        <td>
                                            @if($record->phone != '')
                                                <a href="tel:{{$record->phone}}">{{$record->phone}}</a>
                                            @endif
                                        </td>
                                        <td>{{$record->age > 0 ? $record->age : ''}} </td>
                                        <td>
                                            <span class="tablesaw-cell-content"><span class="badge tessera-badge {{$record->state > 0 ? ($record->state == 2 ? 'active' : 'suspended') : 'due'}}">{{$record->state > 0 ? ($record->state == 2 ? 'Tesserato' : 'Sospeso') : 'Non tesserato'}}</span></span>
                                        </td>
                                        <td>
                                            <span class="tablesaw-cell-content"><span class="badge tessera-badge {{$record->status > 0 ? ($record->status == 2 ? 'active' : 'suspended') : ''}}">{{$record->status > 0 ? ($record->status == 2 ? 'Attivo' : 'Sospesa') : ''}}</span></span>
                                            <b class=" tablesaw-cell-label">Scadenza tessera</b>
                                            <span class="tablesaw-cell-content d-flex align-items-center">
                                                {{$record->status ? 'Scadenza: ' : ($record->date != '' ? 'Scaduto : ' : '')}} {{$record->date != '' ? date("d/m/Y", strtotime($record->date)) : ''}}
                                            </span>
                                        </td>
                                        <td>
                                            @if($record->certificate != '')
                                                <b class=" tablesaw-cell-label">Scadenza certificato</b>
                                                <span class="tablesaw-cell-content d-flex align-items-center">
                                                    @if($record->certificate < date("Y-m-d"))
                                                        <i class="ico--ui check suspended me-2"></i>
                                                        Scaduto :
                                                    @endif
                                                    @if($record->certificate >= date("Y-m-d") && $record->certificate < date("Y-m-d", strtotime("+1 month")))
                                                        <i class="ico--ui check due me-2"></i>
                                                        In scadenza:
                                                    @endif
                                                    @if($record->certificate >= date("Y-m-d", strtotime("+1 month")))
                                                        <i class="ico--ui check active me-2"></i>
                                                        Scadenza:
                                                    @endif
                                                    {{$record->certificate != '' ? date("d/m/Y", strtotime($record->certificate)) : ''}}
                                                </span>
                                            @endif
                                        </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>
                                        </td>
                                    </tr>
                                @endforeach
                            @endif
                        </tbody>
                    </table>
                </section>
            @else
                <a name="top"></a>
                <a style="margin-top:20px" class="btn--ui lightGrey" href="/{{$from != '' ? ($from . '?showFilters=1') : 'members'}}"><i class="fa-solid fa-arrow-left"></i></a><br><br>
                @if (session()->has('success'))
                    <div class="alert alert-success" role="alert">
                        {{ session()->get('success') }}
                    </div>
                @endif
                @if (session()->has('error'))
                    <div class="alert alert-danger" role="alert">
                        {{ session()->get('error') }}
                    </div>
                @endif
                <div class="container-fluid">
                    <div class="row mb-3">
                        <div class="col-md-7 col-xl-8 p-3">
                            <div class="section--tab d-flex">
                                <h4 style="cursor:pointer;{{$type == 'dati' ? 'border-bottom:2px solid var(--color-blu); color:var(--color-blu);' : ''}}" wire:click="change('dati')">Anagrafica</h4>
                                <h4 style="cursor:pointer;{{$type == 'tesseramento' ? 'border-bottom:2px solid var(--color-blu); color:var(--color-blu);' : ''}}" wire:click="change('tesseramento')">Tesseramento</h4>
                                <h4 style="cursor:pointer;{{$type == 'corsi' ? 'border-bottom:2px solid var(--color-blu); color:var(--color-blu);' : ''}}" wire:click="change('corsi')">Corsi e Abbonamenti</h4>
                                <h4 style="cursor:pointer;{{$type == 'presenze' ? 'border-bottom:2px solid var(--color-blu); color:var(--color-blu);' : ''}}" wire:click="change('presenze')">Presenze</h4>
                                <h4 style="cursor:pointer;{{$type == 'gruppi' ? 'border-bottom:2px solid var(--color-blu); color:var(--color-blu);' : ''}}" wire:click="change('gruppi')">Gruppi</h4>
                            </div>
                            <div class="row">
                                @if($type == 'dati')
                                    <div class="form--wrapper d-flex">
                                        <form class="form--utente d-flex">
                                            <div class="form--col" style="width:100%">
                                                <div class="row g-3">
                                                    <div class="col-md-6 col-xxl-3">
                                                        <label for="first_name" class="form-label">Nome</label>
                                                        <input class="form-control @error('first_name') is-invalid @enderror" type="text" id="first_name" placeholder="Nome" wire:model="first_name" style="text-transform:uppercase">
                                                    </div>
                                                    <div class="col-md-6 col-xxl-3">
                                                        <label for="last_name" class="form-label">Cognome</label>
                                                        <input class="form-control @error('last_name') is-invalid @enderror" type="text" id="last_name" placeholder="Cognome" wire:model="last_name" style="text-transform:uppercase">
                                                    </div>
                                                    <div class="col-md-6 col-xxl-3">
                                                        <label for="email" class="form-label">Sesso</label>
                                                        <select id="gender" class="form-select @error('gender') is-invalid @enderror" aria-label="Sesso" wire:model="gender">
                                                            <option value="">
                                                            <option value="M">Uomo
                                                            <option value="D">Donna
                                                            <option value="O">Altro
                                                        </select>
                                                    </div>
                                                    <div class="col-md-6 col-xxl-3">
                                                        <label for="inputDate" class="form-label">Data di nascita {!!$age != '' ? ' <b style="font-size:14px;">(' . $age . ')</b>' : ''!!}</label>
                                                        <div class="input-group mb-3">
                                                            <div style="width:100%">
                                                                <input class="form-control @error('birth_date') is-invalid @enderror" type="date" id="birth_date" placeholder="Data di nascita" wire:model="birth_date">
                                                            </div>
                                                            <div style="width:100%; text-align:center;">{!!$under18 ? '<span style="color:red;font-weight:bold;font-size:12px;">&nbsp;MINORENNE</span>' : ''!!}</div>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="row g-3">
                                                    <div class="col-md-6 col-xxl-3">
                                                        <label for="birth_nation_id" class="form-label">Nazione di Nascita</label>
                                                        <select id="birth_nation_id" class="form-select nationBirthClass @error('birth_nation_id') is-invalid @enderror" aria-label="Nazione di nascita" wire:model="birth_nation_id">
                                                            <option value="{{$birth_nation_id}}">{{$this->getNation($birth_nation_id)}}
                                                        </select>
                                                    </div>
                                                    @if($isBirthItaly)
                                                        <div class="col-md-6 col-xxl-3">
                                                            <label for="birth_province_id" class="form-label">Provincia di Nascita</label>
                                                            <select id="birth_province_id" class="form-select provinceBirthClass @error('birth_province_id') is-invalid @enderror" aria-label="Provincia di nascita" wire:model="birth_province_id">
                                                                <option value="{{$birth_province_id}}">{{$this->getProvince($birth_province_id)}}
                                                            </select>
                                                        </div>
                                                        <div class="col-xl-6">
                                                            <label for="birth_city_id" class="form-label">Comune di Nascita</label>
                                                            <select id="birth_city_id" class="form-select cityBirthClass @error('birth_city_id') is-invalid @enderror" aria-label="Comune di nascita" wire:model="birth_city_id" >
                                                                <option value="{{$birth_city_id}}">{{$this->getCity($birth_city_id)}}
                                                            </select>
                                                        </div>
                                                    @else
                                                        <div class="col-xl-3">
                                                            <label for="birth_place" class="form-label">Paese di nascita</label>
                                                            <input class="form-control @error('birth_place') is-invalid @enderror" type="text" id="birth_place" placeholder="Paese di nascita" wire:model="birth_place">
                                                        </div>
                                                    @endif
                                                </div>
                                                <div class="row g-3 mt-1">
                                                    <div class="col-xl-6">
                                                        <label for="fiscal_code" class="form-label">Codice fiscale (<a wire:click="getFiscalCode()" style="cursor:pointer;font-size:18px;color: var(--color-blu);font-weight: bold;">calcola</a>)</label>
                                                        <input class="form-control  @error('fiscal_code') is-invalid @enderror" type="text" id="fiscal_code" placeholder="Codice fiscale" wire:model="fiscal_code"  maxlength="16">
                                                        @if($this->error_fc)
                                                            <span style="color:red;font-size:12px">Dati mancanti</span>
                                                        @endif
                                                        @if($this->already_existing)
                                                            <span style="color:red;font-size:12px">Codice fiscale già esistente</span>
                                                         @endif
                                                    </div>
                                                    <div class="col-xl-6">
                                                        <div class="upload-file">
                                                            <label for="formFile" class="form-label">Immagine profilo</label>
                                                            @error('image') <span class="error">{{ $message }}</span> @enderror
                                                            <input class="form-control" type="file" wire:model="image">
                                                            @if ($image)
                                                                <img src="{{ $image->temporaryUrl() }}" style="max-width:200px" alt="Preview">
                                                            @endif
                                                            @if ($image_old)
                                                                @php
                                                                    $fileService = app(App\Services\MemberFileService::class);
                                                                    $imageUrl = $fileService->getFileUrl($image_old);
                                                                @endphp
                                                                @if($imageUrl)
                                                                    <img src="{{ $imageUrl }}" style="max-width:200px" alt="Current Image">
                                                                @endif
                                                            @endif
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="row g-3 mt-1">
                                                    <span class="title-form primary d-block w-100">Residenza</span>
                                                    <div class="col-xl-3" wire:ignore>
                                                        <label for="nation_id" class="form-label">Nazione</label>
                                                        <select id="nation_id" class="form-select nationClass @error('nation_id') is-invalid @enderror" aria-label="Nazione" wire:model="nation_id">
                                                            <option value="{{$nation_id}}">{{$this->getNation($nation_id)}}
                                                        </select>
                                                    </div>
                                                    @if($isItaly)
                                                        <div class="col-xl-3">
                                                            <label for="province_id" class="form-label">Provincia</label>
                                                            <select id="province_id" class="form-select provinceClass @error('province_id') is-invalid @enderror" aria-label="Provincia" wire:model="province_id">
                                                                <option value="{{$province_id}}">{{$this->getProvince($province_id)}}
                                                            </select>
                                                        </div>
                                                        <div class="col-xl-6">
                                                            <label for="city_id" class="form-label">Comune</label>
                                                            <select id="city_id" class="form-select cityClass @error('city_id') is-invalid @enderror" aria-label="Comune" wire:model="city_id">
                                                                <option value="{{$city_id}}">{{$this->getCity($city_id)}}
                                                            </select>
                                                        </div>
                                                    @endif
                                                </div>
                                                <div class="row g-3 mt-1">
                                                    <div class="col-xl-6">
                                                        <label for="address" class="form-label">Indirizzo</label>
                                                        <input class="form-control @error('address') is-invalid @enderror" type="text" id="address" placeholder="Indirizzo" wire:model="address" style="text-transform:uppercase">
                                                    </div>
                                                    <div class="col-xl-3">
                                                        <label for="zip_code" class="form-label">CAP</label>
                                                        <input class="form-control @error('zip_code') is-invalid @enderror" type="text" id="zip_code" placeholder="CAP" wire:model="zip_code" maxlength="5"  >
                                                    </div>
                                                </div>
                                                <div class="row g-3 mt-1">
                                                    <span class="title-form primary d-block w-100">Contatti</span>
                                                    <div class="col-xl-6">
                                                        <label for="email" class="form-label">Email</label>
                                                        <input class="form-control @error('email') is-invalid @enderror" type="text" id="email" placeholder="Email" wire:model="email">
                                                    </div>
                                                    <div class="col-xl-6">
                                                        <label for="phone" class="form-label">Telefono/Cellulare</label>
                                                        <input class="form-control @error('phone') is-invalid @enderror" type="text" id="phone" placeholder="Telefono" wire:model="phone">
                                                    </div>
                                                    <div class="col-xl-6">
                                                        <label for="phone2" class="form-label">Telefono 2</label>
                                                        <input class="form-control" type="text" id="phone2" placeholder="Telefono 2" wire:model="phone2">
                                                    </div>
                                                    <div class="col-xl-6">
                                                        <label for="phone3" class="form-label">Telefono 3</label>
                                                        <input class="form-control" type="text" id="phone3" placeholder="Telefono 3" wire:model="phone3">
                                                    </div>
                                                </div>
                                                <div class="row g-3 mt-1">
                                                    <div class="col-lg-12">
                                                        <input type="checkbox" id="no_send_mail" wire:model="no_send_mail">&nbsp;<label for="birth_place" class="form-label">Non inviare mail ricevuta</label>
                                                    </div>
                                                    <div class="col-lg-12">
                                                        <input type="checkbox" id="exclude_from_records" wire:model="exclude_from_records">&nbsp;<label for="birth_place" class="form-label">Escludi da prima nota e entrate/uscite</label>
                                                    </div>
                                                    @if($dataId > 0)
                                                        <span class="title-form primary d-block w-100">Stato</span>
                                                        <div class="col-12">
                                                            <span class="badge tessera-badge {{$active["status"] == 2 ? 'active' : ($active["status"] == 0 ? 'due' : 'suspended')}}">{{$active["status_text"]}}</span>

                                                        </div>
                                                    @endif
                                                </div>
                                                <div class="row g-3 mt-1" wire:key='reload-{{$selectId}}'>
                                                    <span class="title-form primary d-block w-100">Documento</span>
                                                    <div class="col-xl-6 col-xl-3">
                                                        <label for="document_type" class="form-label">Tipo</label>
                                                        <select class="form-select form-select-lg me-1" aria-label=".form-select-lg example" wire:model="document_type">
                                                            <option value="">--Seleziona--</option>
                                                            <option value="Carta di identità">Carta di identità</option>
                                                            <option value="Passaporto">Passaporto</option>
                                                            <option value="Patente">Patente</option>
                                                            <option value="Permesso di soggiorno">Permesso di soggiorno</option>
                                                        </select>
                                                    </div>
                                                    <div class="col-xl-6 col-xl-3">
                                                        <label for="document_number" class="form-label">Numero</label>
                                                        <input class="form-control" type="text" id="document_number" placeholder="Numero" wire:model="document_number">
                                                    </div>
                                                    <div class="col-xl-6 col-xl-3">
                                                        <label for="document_from" class="form-label">Rilasciato da</label>
                                                        <select class="form-select form-select-lg me-1" aria-label=".form-select-lg example" wire:model="document_from">
                                                            <option value="">--Seleziona--</option>
                                                            <option value="Comune">Comune</option>
                                                            <option value="Motorizzazione">Motorizzazione</option>
                                                            <option value="Ministero degli interni">Ministero degli interni</option>
                                                            <option value="Prefettura">Prefettura</option>
                                                        </select>
                                                    </div>
                                                    <div class="col-xl-6 col-xl-3">
                                                        <label for="document_expire_date" class="form-label">Scadenza</label>
                                                        <input class="form-control" type="date" id="document_expire_date" placeholder="Scadenza" wire:model="document_expire_date">
                                                    </div>
                                                    <div class="col-12">
                                                        <label for="document_files" class="form-label">File</label>
                                                        <input class="form-control" type="file" wire:model="documents" multiple><br>
                                                        <label for="document_files" class="form-label">Caricati</label>
                                                        @if ($document_files !== null && count(array_filter($document_files)) > 0)
                                                        @foreach ($document_files as $idx => $d)
                                                            @if (!empty($d))
                                                                <div class="row">
                                                                    <div class="col-6">
                                                                        @php
                                                                            $fileService = app(App\Services\MemberFileService::class);
                                                                            $fileUrl = $fileService->getFileUrl($d);
                                                                            $fileName = basename($d);
                                                                        @endphp
                                                                        @if($fileUrl)
                                                                            <a href="{{ $fileUrl }}" target="_blank" class="form-label member-file-url">{{ $fileName }}</a>
                                                                        @else
                                                                            <span class="form-label text-muted">{{ $fileName }} (not available)</span>
                                                                        @endif
                                                                    </div>
                                                                    <div class="col-6">
                                                                        <a wire:click="removeDocument({{$idx}},'self')" class="form-label" style="cursor: pointer;"><i class="fa-regular fa-trash-can"></i></a><br>
                                                                    </div>
                                                                </div>
                                                            @endif
                                                        @endforeach
                                                    @endif
                                                    </div>
                                                </div>
                                                @if($under18)
                                                    <div class="row g-3 mt-1">
                                                        <span class="title-form primary d-block w-100">Genitore 1</span>
                                                        <div class="col-xl-6">
                                                            <label for="father_name" class="form-label"><b>Nominativo</b></label>
                                                            <input class="form-control" type="text" id="father_name" placeholder="Nome" wire:model="father_name">
                                                        </div>
                                                        <div class="col-xl-6">
                                                            <label for="father_name" class="form-label"><b>Email</b></label>
                                                            <input class="form-control" type="text" id="father_email" placeholder="Email" wire:model="father_email">
                                                        </div>
                                                        <div class="col-xl-6">
                                                            <label for="father_name" class="form-label"><b>Telefono</b></label>
                                                            <input class="form-control" type="text" id="father_phone" placeholder="Telefono" wire:model="father_phone">
                                                        </div>
                                                        <div class="col-xl-6">
                                                            <label for="father_name" class="form-label"><b>Codice fiscale</b></label>
                                                            <input class="form-control" type="text" id="father_fiscal_code" placeholder="Codice fiscale" wire:model="father_fiscal_code" maxlength="16">
                                                        </div>
                                                        <div class="col-xl-6">
                                                            <label for="father_name" class="form-label"><b>Numero del documento</b></label>
                                                            <input class="form-control" type="text" id="father_doc_number" placeholder="Numero documento" wire:model="father_doc_number">
                                                        </div>
                                                        <div class="col-xl-6">
                                                            <label for="father_name" class="form-label"><b>Tipo documento</b></label>
                                                            <select class="form-select form-select-lg me-1" aria-label=".form-select-lg example" wire:model="father_doc_type">
                                                                <option value="">Seleziona il tipo documento</option>
                                                                <option value="Carta di identità">Carta di identità</option>
                                                                <option value="Passaporto">Passaporto</option>
                                                                <option value="Patente">Patente</option>
                                                                <option value="Permesso di soggiorno">Permesso di soggiorno</option>
                                                            </select>
                                                        </div>
                                                        <div class="col-12">
                                                            <label for="father_documents" class="form-label">File</label>
                                                            <input class="form-control" type="file" wire:model="father_documents" multiple><br>
                                                            <label for="father_documents" class="form-label">Caricati</label>
                                                            @if ($father_document_files !== null && count(array_filter($father_document_files)) > 0)
                                                                @foreach ($father_document_files as $idx => $d)
                                                                    @if (!empty($d))
                                                                        <div class="row">
                                                                            <div class="col-6">
                                                                                @php
                                                                                    $fileService = app(App\Services\MemberFileService::class);
                                                                                    $fileUrl = $fileService->getFileUrl($d);
                                                                                    $fileName = basename($d);
                                                                                @endphp
                                                                                @if($fileUrl)
                                                                                    <a href="{{ $fileUrl }}" target="_blank" class="form-label member-file-url">{{ $fileName }}</a>
                                                                                @else
                                                                                    <span class="form-label text-muted">{{ $fileName }} (not available)</span>
                                                                                @endif
                                                                            </div>
                                                                            <div class="col-6">
                                                                                <a wire:click="removeDocument({{$idx}},'father')" class="form-label" style="cursor: pointer;"><i class="fa-regular fa-trash-can"></i></a><br>
                                                                            </div>
                                                                        </div>
                                                                    @endif
                                                                @endforeach
                                                            @endif
                                                        </div>
                                                    </div>
                                                    <div class="row g-3 mt-1">
                                                        <span class="title-form primary d-block w-100">Genitore 2</span>
                                                        <div class="col-xl-6">
                                                            <label for="mother_name" class="form-label"><b>Nominativo</b></label>
                                                            <input class="form-control " type="text" id="mother_name" placeholder="Nome genitore 2" wire:model="mother_name">
                                                        </div>
                                                        <div class="col-xl-6">
                                                            <label for="mother_name" class="form-label"><b>Email</b></label>
                                                            <input class="form-control " type="text" id="mother_email" placeholder="Email" wire:model="mother_email">
                                                        </div>
                                                        <div class="col-xl-6">
                                                            <label for="mother_name" class="form-label"><b>Telefono</b></label>
                                                            <input class="form-control " type="text" id="mother_phone" placeholder="Telefono" wire:model="mother_phone">
                                                        </div>
                                                        <div class="col-xl-6">
                                                            <label for="mother_name" class="form-label"><b>Codice fiscale</b></label>
                                                            <input class="form-control " type="text" id="mother_fiscal_code" placeholder="Codice fiscale" wire:model="mother_fiscal_code" maxlength="16">
                                                        </div>
                                                        <div class="col-xl-6">
                                                            <label for="mother_name" class="form-label"><b>Numero del documento</b></label>
                                                            <input class="form-control " type="text" id="mother_doc_number" placeholder="Numero documento" wire:model="mother_doc_number">
                                                        </div>
                                                        <div class="col-xl-6">
                                                            <label for="mother_name" class="form-label"><b>Tipo documento</b></label>
                                                            <select class="form-select form-select-lg me-1" aria-label=".form-select-lg example" wire:model="mother_doc_type">
                                                                <option value="">Seleziona il tipo documento</option>
                                                                <option value="Carta di identità">Carta di identità</option>
                                                                <option value="Passaporto">Passaporto</option>
                                                                <option value="Patente">Patente</option>
                                                                <option value="Permesso di soggiorno">Permesso di soggiorno</option>
                                                            </select>
                                                        </div>
                                                    </div>
                                                    <div class="col-12">
                                                        <label for="mother_documents" class="form-label">File</label>
                                                        <input class="form-control" type="file" wire:model="mother_documents" multiple><br>
                                                        <label for="mother_documents" class="form-label">Caricati</label>
                                                        @if ($mother_document_files !== null && count(array_filter($mother_document_files)) > 0)
                                                            @foreach ($mother_document_files as $idx => $d)
                                                                @if (!empty($d))
                                                                    <div class="row">
                                                                        <div class="col-6">
                                                                            @php
                                                                                $fileService = app(App\Services\MemberFileService::class);
                                                                                $fileUrl = $fileService->getFileUrl($d);
                                                                                $fileName = basename($d);
                                                                            @endphp
                                                                            @if($fileUrl)
                                                                                <a href="{{ $fileUrl }}" target="_blank" class="form-label member-file-url">{{ $fileName }}</a>
                                                                            @else
                                                                                <span class="form-label text-muted">{{ $fileName }} (not available)</span>
                                                                            @endif
                                                                        </div>
                                                                        <div class="col-6">
                                                                            <a wire:click="removeDocument({{$idx}},'mother')" class="form-label" style="cursor: pointer;"><i class="fa-regular fa-trash-can"></i></a><br>
                                                                        </div>
                                                                    </div>
                                                                @endif
                                                            @endforeach
                                                        @endif
                                                    </div>
                                                @endif
                                                <div class="row g-3 mt-1">
                                                    <span class="title-form primary d-block w-100">Certificato Medico</span>
                                                    @if($dataId > -1)
                                                        @if(!$addCertificate && !$updateCertificate)
                                                            <table class="table tablesaw tableHead tablesaw-stack" >
                                                                <thead>
                                                                    <tr>
                                                                        <th scope="col">Tipo</th>
                                                                        <th scope="col">Scadenza</th>
                                                                        <th scope="col"></th>
                                                                        <th scope="col">...</th>
                                                                    </tr>
                                                                </thead>
                                                                <tbody >
                                                                    @foreach($member_certificates as $member_certificate)
                                                                        <tr>
                                                                            <td>{{$member_certificate->type == 'A' ? 'Agonistico' : 'Non agonistico'}}</td>
                                                                            <td>{{$member_certificate->expire_date ? date("d/m/Y", strtotime($member_certificate->expire_date)) : ''}}</td>
                                                                            <td>
                                                                                @if($member_certificate->filename != '')
                                                                                    @php
                                                                                        $fileService = app(App\Services\MemberFileService::class);
                                                                                        $certificateUrl = $fileService->getFileUrl($member_certificate->filename);
                                                                                    @endphp
                                                                                    @if($certificateUrl)
                                                                                        <a href="{{ $certificateUrl }}" target="_blank" class="member-file-url">Visualizza</a>
                                                                                    @else
                                                                                        <span class="text-muted">File non disponibile</span>
                                                                                    @endif
                                                                                @endif
                                                                            </td>
                                                                            <td>
                                                                                <button type="button" class="btn" wire:click="editCertificate({{ $member_certificate->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="deleteCertificate({{ $member_certificate->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>
                                                                            </td>
                                                                        </tr>
                                                                    @endforeach
                                                                </tbody>
                                                            </table>
                                                            <button class="btn--ui primary"wire:click.prevent="addCertificate()" style="max-width:200px">Aggiungi</button>
                                                        @else
                                                            <div class="form--wrapper">
                                                                <form class="form--utente">
                                                                    <div class="row ">
                                                                        <div class="col-md-6">
                                                                            <label for="certificate_type" class="form-label">Tipo</label>
                                                                            <select id="certificate_type" class="form-select certificate_type" aria-label="Tessera" wire:model="certificate_type">
                                                                                <option value="">--Seleziona--
                                                                                <option value="N">Non agonistico
                                                                                <option value="A">Agonistico
                                                                            </select>
                                                                        </div>
                                                                        <div class="col-md-6">
                                                                            <label for="certificate_expire_date" class="form-label">Data scadenza</label>
                                                                            <input class="form-control @error('certificate_expire_date') is-invalid @enderror" type="date" id="certificate_expire_date" placeholder="Data scadenza" wire:model="certificate_expire_date">
                                                                        </div>
                                                                    </div>
                                                                    <div class="col-12">
                                                                        <div class="upload--image_box d-flex align-items-center justify-content-center flex-column">
                                                                            <input class="form-control" type="file" wire:model="certificate_filename">
                                                                        </div>
                                                                        <p class="caption text-center mt-1">Formati consentiti: .jpg, .pdf, .docx</p>
                                                                        @if($certificate_filename_old != '')
                                                                            @php
                                                                                $fileService = app(App\Services\MemberFileService::class);
                                                                                $certificateUrl = $fileService->getFileUrl($certificate_filename_old);
                                                                            @endphp
                                                                            @if($certificateUrl)
                                                                                <br><a href="{{ $certificateUrl }}" target="_blank">Visualizza certificato corrente</a>
                                                                            @endif
                                                                        @endif
                                                                    </div>
                                                                </form>
                                                            </div>
                                                            <div class="d-flex justify-content-end mt-3">
                                                                <button class="btn--ui lightGrey me-2" wire:click.prevent="cancelCertificate()">Annulla</button>
                                                                @if($addCertificate)
                                                                    <button class="btn--ui primary" wire:click.prevent="storeCertificate()">Salva</button>
                                                                @endif
                                                                @if($updateCertificate)
                                                                    <button class="btn--ui primary" wire:click.prevent="updateCertificate()">Salva</button>
                                                                @endif
                                                            </div>
                                                        @endif
                                                    @else
                                                        <label for="last_name" class="form-label">Prima di caricare un certificato salva l'utente</label>
                                                    @endif
                                                </div>
                                            </div>
                                        </form>
                                    </div>
                                @endif
                                @if($type == 'tesseramento')
                                    @if($dataId > 0)
                                        @if(!$addCard && !$updateCard)
                                            <table class="table tablesaw tableHead tablesaw-stack" id="tablesaw-350-1">
                                                <thead>
                                                    <tr>
                                                        <th scope="col">Tesseramento</th>
                                                        <th scope="col">Numero</th>
                                                        <th scope="col">Scadenza</th>
                                                        <th scope="col">...</th>
                                                    </tr>
                                                </thead>
                                                <tbody id="checkall-target">
                                                    @foreach($member_cards as $member_card)
                                                        <tr>
                                                            <td>{{$member_card->card->name}}</td>
                                                            <td>{{$member_card->number}}</td>
                                                            <td>{{$member_card->expire_date ? date("d/m/Y", strtotime($member_card->expire_date)) : ''}}</td>
                                                            <td>
                                                                <button type="button" class="btn" wire:click="editCard({{ $member_card->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="deleteCard({{ $member_card->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>
                                                            </td>
                                                        </tr>
                                                    @endforeach

                                                </tbody>
                                            </table>
                                            <button class="btn--ui primary"wire:click.prevent="addCard()" style="max-width:200px">Aggiungi</button>
                                        @else
                                            <div class="form--wrapper">
                                                <form class="form--utente">
                                                    <div class="row g-3">
                                                        <div class="col-md-6">
                                                            <label for="card_card_id" class="form-label">Tessera</label>
                                                            <select id="card_card_id" class="form-select card_card_id @error('card_card_id') is-invalid @enderror" aria-label="Tessera" wire:model="card_card_id">
                                                                <option value="">--Seleziona--
                                                                @foreach($cards as $card)
                                                                    <option value="{{$card->id}}">{{$card->name}}
                                                                @endforeach
                                                            </select>
                                                        </div>
                                                        <div class="col-md-6">
                                                            <label for="card_number" class="form-label">Numero</label>
                                                            <input class="form-control @error('card_number') is-invalid @enderror" type="text" id="card_number" placeholder="Numero" wire:model="card_number">
                                                        </div>
                                                    </div>
                                                    <div class="row g-3 mt-1">
                                                        <div class="col-md-6">
                                                            <label for="card_date" class="form-label">Data rilascio tessera</label>
                                                            <input class="form-control" type="date" id="card_date" placeholder="Data" wire:model="card_date">
                                                        </div>
                                                        <div class="col-md-6">
                                                            <label for="card_accept_date" class="form-label">Data accettazione</label>
                                                            <input class="form-control" type="date" id="card_accept_date" placeholder="Data accettazione" wire:model="card_accept_date">
                                                        </div>
                                                    </div>
                                                    <div class="row g-3 mt-1">
                                                        <div class="col-md-6">
                                                            <label for="card_date" class="form-label">Disciplina 1</label>
                                                            <select id="card_discipline1_id" class="form-select " aria-label="Disciplina 1" wire:model="card_discipline1_id">
                                                                <option value="">--Seleziona--
                                                                @foreach($disciplines as $d)
                                                                    <option value="{{$d->id}}">{{$d->name}}
                                                                @endforeach
                                                            </select>
                                                        </div>
                                                        <div class="col-md-6">
                                                            <label for="card_date" class="form-label">Disciplina 2</label>
                                                            <select id="card_discipline2_id" class="form-select " aria-label="Disciplina 2" wire:model="card_discipline2_id">
                                                                <option value="">--Seleziona--
                                                                @foreach($disciplines as $d)
                                                                    <option value="{{$d->id}}">{{$d->name}}
                                                                @endforeach
                                                            </select>
                                                        </div>
                                                    </div>
                                                    @if($card_discipline2_id > 0)
                                                        <div class="row g-3 mt-1">
                                                            <div class="col-md-6">
                                                                <label for="card_date" class="form-label">Disciplina 3</label>
                                                                <select id="card_discipline3_id" class="form-select " aria-label="Disciplina 3" wire:model="card_discipline3_id">
                                                                    <option value="">--Seleziona--
                                                                    @foreach($disciplines as $d)
                                                                        <option value="{{$d->id}}">{{$d->name}}
                                                                    @endforeach
                                                                </select>
                                                            </div>
                                                        </div>
                                                    @endif
                                                </form>
                                            </div>
                                            <br>
                                            <div class="row g-3 mt-2">
                                                <div class="col-md-12">
                                                    <button class="btn--ui lightGrey" wire:click.prevent="cancelCard()">Annulla</button>
                                                    @if($addCard)
                                                        <button class="btn--ui primary" wire:click.prevent="storeCard()">Salva</button>
                                                    @endif
                                                    @if($updateCard)
                                                        <button class="btn--ui primary" wire:click.prevent="updateCard()">Salva</button>
                                                    @endif
                                                </div>
                                            </div>
                                        @endif
                                    @endif
                                @endif

                                @if($type == 'presenze')

                                    <div class="form--wrapper">
                                        <div class="row">
                                            <div class="col-md-6">
                                                <select class="form-control" wire:model="presenceYearFilter">
                                                    <option value="">-- Stagione --</option>
                                                    @foreach($presenceYears as $y)
                                                        <option value="{{$y}}">{{$y}}</option>
                                                    @endforeach
                                                </select>
                                            </div>

                                            <div class="col-md-6">
                                                <select class="form-control" wire:model="presenceCourseFilter" @if(empty($presenceCourses)) disabled @endif>
                                                    <option value="">-- Corso --</option>
                                                    @foreach($presenceCourses as $c)
                                                        <option value="{{$c->id}}">
                                                            {{$c->getDetailsName()}}
                                                        </option>
                                                    @endforeach
                                                </select>
                                            </div>
                                        </div>

                                        <br>

                                        <div class="row align-items-center">
                                            <div class="col">
                                                <div class="box-presenze">
                                                    <span><b>Presenze</b>: {{ $presenze }}</span>
                                                </div>
                                            </div>
                                            <div class="col">
                                                <div class="box-assenze">
                                                    <span><b>Assenze</b>: {{ $assenze }}</span>
                                                </div>
                                            </div>
                                            <div class="col"@if (!empty($recuperi)) style="border-right: 1px solid gray"@endif>
                                                <div class="box-annullate">
                                                    <span><b>Annullate</b>: {{ $annullate }}</span>
                                                </div>
                                            </div>
                                            @if (!empty($recuperi))
                                                <div class="col">
                                                    <div class="box-presenze text-start">
                                                        @foreach ($recuperi as $name => $count)
                                                            <span><b>{!! $name !!}</b>: {{ $count }}</span><br>
                                                        @endforeach
                                                    </div>
                                                </div>
                                            @endif
                                        </div>

                                        <div class="row">
                                            <div class="col-md-12">
                                                <div class="presenzechart-wrapper">
                                                    <canvas id="presenzeChart" style="padding:20px"></canvas>
                                                    <button class="btn--ui download-png" onclick="downloadChart('presenzeChart')" data-bs-toggle="popover"
                                                        data-bs-trigger="hover focus" data-bs-placement="bottom" data-bs-content="Scarica grafico">
                                                        <i class="fas fa-download"></i>
                                                    </button>
                                                </div>
                                            </div>
                                        </div>

                                        @if (!empty($member_presences))
                                            <div class="row" style="height: 300px; overflow:auto;">
                                                <div class="col-md-12">
                                                    <table class="table tablesaw tableHead tablesaw-stack tabella--presenze" style="min-width:700px">
                                                        <thead>
                                                            <tr>
                                                                <th style="width: 20%">Data</th>
                                                                <th style="width: 20%">Orario</th>
                                                                <th style="width: 15%">Stato</th>
                                                                <th style="width: 45%">Motivazione</th>
                                                            </tr>
                                                        </thead>
                                                        <tbody>
                                                            @foreach($member_presences as $mp)
                                                                <tr>
                                                                    <td>{{ date("d/m/Y", strtotime($mp["from"])) }}</td>
                                                                    <td>{{ date("H:i", strtotime($mp["from"])) }} - {{ date("H:i", strtotime($mp["to"])) }}</td>
                                                                    <td>{!! $mp["status"] !!}</td>
                                                                    <td>{!! $mp["motivation"] !!}</td>
                                                                </tr>
                                                            @endforeach
                                                        </tbody>
                                                    </table>
                                                </div>
                                            </div>
                                        @endif
                                    </div>

                                @endif

                                @if($type == 'gruppi')
                                    <form class="form--tesseramento mt-4">
                                        @livewire('categories')
                                        @if(false)
                                            <div class="tessera--added d-flex align-items-center justify-content-between mt-4 mb-3">
                                                <select id="category_category_id" class="form-select categoriesClass @error('category_category') is-invalid @enderror" aria-label="Gruppo" wire:model="category_category_id" style="width:100%;">
                                                        <option value="">--Seleziona--
                                                        @foreach($categories as $category)
                                                            <option value="{{$category["id"]}}">{{$category["name"]}}
                                                        @endforeach
                                                    </select>
                                                <button class="btn--ui_outline" wire:click.prevent="storeCategory()" style="margin-left:20px"><i class="ico--ui gruppi"></i>aggiungi</button>
                                            </div>
                                        @endif
                                        <span style="color:red">{!!$groupMsg!!}</span>
                                        <div class="mt-3"></div>
                                        @foreach($member_categories as $member_category)
                                            <div class="tessera--added d-flex align-items-center gap-5">
                                                <div class="tessera--added_name d-flex align-items-center gap-3">
                                                    <i class="fa-solid fa-users"></i>
                                                    <div class="title--tessera_added">
                                                        <h4>{{$member_category->category->getTree()}}</h4>
                                                    </div>
                                                </div>
                                                <button type="button" class="btn" onclick="confirm('Sei sicuro?') || event.stopImmediatePropagation()" wire:click="deleteCategory({{ $member_category->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>
                                            </div>
                                        @endforeach
                                    </form>
                                @endif
                                @if($type == 'corsi')
                                    @if($dataId > 0)
                                        @if(!$addCourse && !$updateCourse)
                                            @if($active["status"] == 0 && !$hasCertificate)
                                                <div class="row mb-3">
                                                    <div class="col-md-12">
                                                        <div class="alert alert-info" role="alert">
                                                            {{-- <strong>Attenzione:</strong> Per aggiungere corsi è necessario avere un tesseramento attivo o un certificato medico valido. --}}
                                                            <strong>Info:</strong> Non sono presenti un tesseramento attivo o un certificato medico valido.
                                                        </div>
                                                    </div>
                                                </div>
                                            @elseif($active["status"] == 0)
                                                <div class="row mb-3">
                                                    <div class="col-md-12">
                                                        <div class="alert alert-info" role="alert">
                                                            <strong>Info:</strong> Il tesseramento non è attivo, ma è presente un certificato medico valido.
                                                        </div>
                                                    </div>
                                                </div>
                                            @elseif(!$hasCertificate)
                                                <div class="row mb-3">
                                                    <div class="col-md-12">
                                                        <div class="alert alert-info" role="alert">
                                                            <strong>Info:</strong> Non è presente un certificato medico valido, ma il tesseramento è attivo.
                                                        </div>
                                                    </div>
                                                </div>
                                            @endif
                                            <div class="row">
                                                <div class="col-md-12">
                                                    <h4 class="text-uppercase">Abbonamenti</h4>
                                                    @if ((is_array($member_subscriptions) && empty($member_subscriptions)) || $member_subscriptions->count() == 0)
                                                    <div class="alert alert-warning" role="alert">
                                                        Nessun abbonamento associato all'utente
                                                    </div>
                                                    @else
                                                    <table class="table tablesaw tableHead tablesaw-stack tabella--abbonamenti" id="tablesaw-abbonamenti" style="min-width:800px">
                                                        <tbody id="checkall-target">
                                                            @foreach($member_subscriptions as $member_subscription)
                                                                <tr>
                                                                    <td style="width:30%;" colspan="1">
                                                                        <b>{{$member_subscription->subscription->name}}</b><br>
                                                                    </td>
                                                                    <td style="width:20%;">
                                                                        {{date('d/m/Y', strtotime($member_subscription->date_from))}} - {{date('d/m/Y', strtotime($member_subscription->date_to))}}
                                                                    </td>
                                                                    <td style="width:30%;">
                                                                        @if($member_subscription->notes != '')
                                                                            <b>Note: </b>
                                                                            {{$member_subscription->notes}}
                                                                        @endif
                                                                    </td>
                                                                    <td style="text-align:right;width:10%;">
                                                                        @php
                                                                            $status = $member_subscription->getStatus();
                                                                        @endphp
                                                                        <a href="/rates?member_id={{$member_subscription->member_id}}&member_subscription_id={{$member_subscription->id}}"><span class="badge tessera-badge {{$status == 0 ? 'due' : ($status == 1 ? 'active' : 'suspended')}}">{{$status == 0 ? 'Da pagare' : ($status == 1 ? 'Pagato' : 'Sospeso')}}</span></a>
                                                                    </td>
                                                                    <td style="text-align:right;width:10%;">
                                                                        <div class="row">
                                                                            <div class="col-6">
                                                                                <button style="float:left;" type="button" class="btn" wire:click="editSubscription({{ $member_subscription->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>
                                                                            </div>
                                                                            <div class="col-6">
                                                                                <button type="button" class="btn" onclick="confirm('Sei sicuro?') || event.stopImmediatePropagation()" wire:click="deleteSubscription({{ $member_subscription->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>
                                                                            </div>
                                                                        </div>
                                                                    </td>
                                                                </tr>
                                                            @endforeach
                                                        </tbody>
                                                    </table>
                                                    @endif
                                                </div>

                                                <div class="col-md-12 mt-5">
                                                    <h4 class="text-uppercase">Corsi</h4>
                                                    @if ((is_array($member_courses) && empty($member_courses)) || $member_courses->count() == 0)
                                                    <div class="alert alert-warning" role="alert">
                                                        Nessun corso associato all'utente
                                                    </div>
                                                    @else
                                                    <table class="table tablesaw tableHead tablesaw-stack tabella--corsi" id="tablesaw-350-2" style="min-width:800px">
                                                        <tbody id="checkall-target">
                                                            @foreach($member_courses as $member_course)
                                                                <tr>
                                                                    <td style="width:20%;" colspan="1">
                                                                        <b>{{$member_course->course->discipline?->name ?? ''}}{{($member_course->course->discipline?->name ? ' - ' : '') . $member_course->course->name}}</b><br>
                                                                    </td>
                                                                    <td style="width:30%;">
                                                                        {{$member_course->course->level->name ?? ""}} - {{$member_course->course->frequency->name ?? ""}}
                                                                    </td>
                                                                    <td style="width:20%">
                                                                        @php
                                                                            $ok = false;
                                                                        @endphp
                                                                        @foreach(json_decode($member_course->when) as $xx => $x)
                                                                            @if($xx > 0)
                                                                                <br>
                                                                            @endif
                                                                            @foreach($x->day as $zz => $d)
                                                                                {{$zz > 0 ? '- ' : ''}}{{$d}}
                                                                            @endforeach
                                                                            <br>
                                                                            @if($x->from != '' && $x->to != '')
                                                                                h {{$x->from}} - {{$x->to}}
                                                                            @endif
                                                                            @php
                                                                                $ok = $x->from != '';
                                                                            @endphp
                                                                        @endforeach
                                                                        @if(!$ok && $member_course->course->when != '')
                                                                            @foreach(json_decode($member_course->course->when) as $xx => $x)
                                                                                @php
                                                                                    $ok = true;
                                                                                @endphp
                                                                                @if($xx > 0)
                                                                                    <br>
                                                                                @endif
                                                                                @foreach($x->day as $zz => $d)
                                                                                    {{$zz > 0 ? '- ' : ''}}{{$d}}
                                                                                @endforeach
                                                                                <br>
                                                                                @if($x->from != '')
                                                                                    h {{$x->from}} - {{$x->to}}
                                                                                @endif
                                                                            @endforeach
                                                                        @endif
                                                                    </td>
                                                                    <td style="text-align:right;@if($member_course->notes != '') width:10%; @else width:20%; @endif">
                                                                        @php
                                                                            $status = $member_course->getStatus();
                                                                        @endphp
                                                                        <a href="/rates?member_id={{$member_course->member_id}}&member_course_id={{$member_course->id}}"><span class="badge tessera-badge {{$status == 0 ? 'due' : ($status == 1 ? 'active' : 'suspended')}}">{{$status == 0 ? 'Da pagare' : ($status == 1 ? 'Pagato' : 'Sospeso')}}</span></a>
                                                                    </td>
                                                                    <td style="text-align:right;width:10%;">
                                                                        <div class="row">
                                                                            <div class="col-6">
                                                                                <button style="float:left;" type="button" class="btn" wire:click="editCourse({{ $member_course->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>
                                                                            </div>
                                                                            <div class="col-6">
                                                                                <button type="button" class="btn" onclick="confirm('Sei sicuro?') || event.stopImmediatePropagation()" wire:click="deleteCourse({{ $member_course->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>
                                                                            </div>
                                                                        </div>
                                                                    </td>
                                                                    @if($member_course->notes != '')
                                                                    <td style="text-align:left;width:10%;padding:0;padding-top:15px;">
                                                                            <button type="button" class="btn" wire:click="showHideCourse({{ $member_course->id }})">
                                                                                @if(in_array($member_course->id, $showCourse))
                                                                                    <i class="fa-solid fa-chevron-circle-up"></i>
                                                                                @else
                                                                                    <i class="fa-solid fa-chevron-circle-down"></i>
                                                                                @endif
                                                                            </button>&nbsp;
                                                                    </td>
                                                                    @endif
                                                                </tr>
                                                                {{-- <tr>
                                                                    <td style="width:30%" colspan="2">
                                                                        {{date("d/m/Y", strtotime($member_course->date_from))}} - {{date("d/m/Y", strtotime($member_course->date_to))}}
                                                                    </td>
                                                                    <td style="width:30%"colspan="5">
                                                                        @php
                                                                            $ok = false;
                                                                        @endphp
                                                                        @foreach(json_decode($member_course->when) as $xx => $x)
                                                                            @if($xx > 0)
                                                                                <br>
                                                                            @endif
                                                                            @foreach($x->day as $zz => $d)
                                                                                {{$zz > 0 ? '-' : ''}}{{$d}}
                                                                            @endforeach
                                                                            @if($x->from != '' && $x->to != '')
                                                                                h {{$x->from}} - {{$x->to}}
                                                                            @endif
                                                                            @php
                                                                                $ok = $x->from != '';
                                                                            @endphp
                                                                        @endforeach
                                                                        @if(!$ok && $member_course->course->when != '')
                                                                            @foreach(json_decode($member_course->course->when) as $xx => $x)
                                                                                @php
                                                                                    $ok = true;
                                                                                @endphp
                                                                                @if($xx > 0)
                                                                                    <br>
                                                                                @endif
                                                                                @foreach($x->day as $zz => $d)
                                                                                    {{$zz > 0 ? '-' : ''}}{{$d}}
                                                                                @endforeach
                                                                                @if($x->from != '')
                                                                                    h {{$x->from}} - {{$x->to}}
                                                                                @endif
                                                                            @endforeach
                                                                        @endif
                                                                    </td>
                                                                </tr> --}}
                                                                @if(in_array($member_course->id, $showCourse))
                                                                    @if(false)
                                                                        <tr>
                                                                            <td colspan="5">
                                                                                <a class="{{$this->getSubscriptionStatus($member_course->subscribed, $member_course->id)}}" wire:click="setCreateSubscription({{$member_course->subscribed}}, {{$member_course->id}})" style="float:none; width:150px;{{$this->getSubscriptionStatus($member_course->subscribed,$member_course->id) == 'blue' || $this->getSubscriptionStatus($member_course->subscribed,$member_course->id) == 'orange' || $this->getSubscriptionStatus($member_course->subscribed,$member_course->id) == 'yellow' ? 'cursor:pointer' : ''}}">Iscrizione</a><br>
                                                                                <a class="{{$this->getMonthStatus(9, $member_course->months, $member_course->id)}}" wire:click="setPayMonth(9, '{{ $member_course->months }}', {{$member_course->id}})" {{in_array($this->getMonthStatus(9, $member_course->months, $member_course->id), ['blue', 'orange', 'yellow', 'orange half']) ? 'style=cursor:pointer' : ''}}>Set</a>&nbsp;
                                                                                <a class="{{$this->getMonthStatus(10, $member_course->months, $member_course->id)}}" wire:click="setPayMonth(10, '{{ $member_course->months }}', {{$member_course->id}})" {{in_array($this->getMonthStatus(10, $member_course->months, $member_course->id), ['blue', 'orange', 'yellow', 'orange half']) ? 'style=cursor:pointer' : ''}}>Ott</a>&nbsp;
                                                                                <a class="{{$this->getMonthStatus(11, $member_course->months, $member_course->id)}}" wire:click="setPayMonth(11, '{{ $member_course->months }}', {{$member_course->id}})" {{in_array($this->getMonthStatus(11, $member_course->months, $member_course->id), ['blue', 'orange', 'yellow', 'orange half']) ?  'style=cursor:pointer' : ''}}>Nov</a>&nbsp;
                                                                                <a class="{{$this->getMonthStatus(12, $member_course->months, $member_course->id)}}" wire:click="setPayMonth(12, '{{ $member_course->months }}', {{$member_course->id}})" {{in_array($this->getMonthStatus(12, $member_course->months, $member_course->id), ['blue', 'orange', 'yellow', 'orange half']) ?  'style=cursor:pointer' : ''}}>Dic</a>&nbsp;
                                                                                <a class="{{$this->getMonthStatus(1, $member_course->months, $member_course->id)}}" wire:click="setPayMonth(1, '{{ $member_course->months }}', {{$member_course->id}})" {{in_array($this->getMonthStatus(1, $member_course->months, $member_course->id), ['blue', 'orange', 'yellow', 'orange half']) ?  'style=cursor:pointer' : ''}}>Gen</a>&nbsp;
                                                                                <a class="{{$this->getMonthStatus(2, $member_course->months, $member_course->id)}}" wire:click="setPayMonth(2, '{{ $member_course->months }}', {{$member_course->id}})" {{in_array($this->getMonthStatus(2, $member_course->months, $member_course->id), ['blue', 'orange', 'yellow', 'orange half']) ?  'style=cursor:pointer' : ''}}>Feb</a>&nbsp;
                                                                                <a class="{{$this->getMonthStatus(3, $member_course->months, $member_course->id)}}" wire:click="setPayMonth(3, '{{ $member_course->months }}', {{$member_course->id}})" {{in_array($this->getMonthStatus(3, $member_course->months, $member_course->id), ['blue', 'orange', 'yellow', 'orange half']) ?  'style=cursor:pointer' : ''}}>Mar</a>&nbsp;
                                                                                <a class="{{$this->getMonthStatus(4, $member_course->months, $member_course->id)}}" wire:click="setPayMonth(4, '{{ $member_course->months }}', {{$member_course->id}})" {{in_array($this->getMonthStatus(4, $member_course->months, $member_course->id), ['blue', 'orange', 'yellow', 'orange half']) ? 'style=cursor:pointer' : ''}}>Apr</a>&nbsp;
                                                                                <a class="{{$this->getMonthStatus(5, $member_course->months, $member_course->id)}}" wire:click="setPayMonth(5, '{{ $member_course->months }}', {{$member_course->id}})" {{in_array($this->getMonthStatus(5, $member_course->months, $member_course->id), ['blue', 'orange', 'yellow', 'orange half']) ? 'style=cursor:pointer' : ''}}>Mag</a>&nbsp;
                                                                                <a class="{{$this->getMonthStatus(6, $member_course->months, $member_course->id)}}" wire:click="setPayMonth(6, '{{ $member_course->months }}', {{$member_course->id}})" {{in_array($this->getMonthStatus(6, $member_course->months, $member_course->id), ['blue', 'orange', 'yellow', 'orange half']) ? 'style=cursor:pointer' : ''}}>Giu</a>&nbsp;
                                                                                <a class="{{$this->getMonthStatus(7, $member_course->months, $member_course->id)}}" wire:click="setPayMonth(7, '{{ $member_course->months }}', {{$member_course->id}})" {{in_array($this->getMonthStatus(7, $member_course->months, $member_course->id), ['blue', 'orange', 'yellow', 'orange half']) ? 'style=cursor:pointer' : ''}}>Lug</a>&nbsp;
                                                                                <a class="{{$this->getMonthStatus(8, $member_course->months, $member_course->id)}}" wire:click="setPayMonth(8, '{{ $member_course->months }}', {{$member_course->id}})" {{in_array($this->getMonthStatus(8, $member_course->months, $member_course->id) , ['blue', 'orange', 'yellow', 'orange half']) ? 'style=cursor:pointer' : ''}}>Ago</a>&nbsp;
                                                                            </td>
                                                                            <td>
                                                                                <button type="button" class="btn" wire:click="editCourse({{ $member_course->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>&nbsp;
                                                                                <button type="button" class="btn" onclick="confirm('Sei sicuro?') || event.stopImmediatePropagation()" wire:click="deleteCourse({{ $member_course->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>
                                                                            </td>
                                                                        </tr>
                                                                    @endif
                                                                    <tr>
                                                                        <td colspan="7">
                                                                            @if($member_course->notes != '')
                                                                                <b>Note</b><br>
                                                                                {{$member_course->notes}}
                                                                            @endif
                                                                            @if($selectedCourseMember == $member_course->id)
                                                                                @if(sizeof($payMonths) > 0 || $createSubscription)
                                                                                    <button class="btn--ui primary" style="color:white" wire:click="newPayment({{$member_course}})">Nuova entrata</button>&nbsp;
                                                                                    <button class="btn--ui primary" style="color:white" wire:click="block({{$member_course}})">Sospendi</button>
                                                                                @endif
                                                                                @if(sizeof($suspendedMonths) > 0)
                                                                                    <button class="btn--ui primary" style="color:white" wire:click="reactivate({{$member_course}})">Riattiva</button>&nbsp;
                                                                                @endif<br>
                                                                            @endif
                                                                        </td>
                                                                    </tr>
                                                                @endif
                                                            @endforeach
                                                        </tbody>
                                                    </table>
                                                    @endif
                                                </div>
                                            </div>
                                            @if($dataId > 0)
                                            <div class="row mt-5">
                                                <div class="col-md-12">
                                                {{-- @if ($active["status"] == 1 || $hasCertificate) --}}
                                                    <button class="btn--ui primary" wire:click.prevent="addCourse()" style="max-width:200px">Aggiungi</button>
                                                {{-- @else --}}
                                                    {{-- <button class="btn--ui lightGrey" disabled style="max-width:200px">Aggiungi corso (non disponibile)</button>
                                                    <small class="text-muted d-block mt-1">Completa prima il tesseramento o carica un certificato medico valido</small> --}}
                                                {{-- @endif --}}
                                                </div>
                                            </div>
                                            @endif
                                        @else
                                            <div class="form--wrapper">
                                                <form class="form--utente">
                                                    <div class="row">
                                                        <div class="col-4 mt-2">
                                                            <label for="subscription_id" class="form-label">Tipologia</label><br>
                                                            <select id="subscription_id" class="form-select" aria-label="Tipologia" wire:model="subscription_id" >
                                                                <option value=""></option>
                                                                <option value="course">Corso</option>
                                                                @foreach($subscriptions as $subscription)
                                                                    <option value="{{$subscription->id}}">{{$subscription->name}}</option>
                                                                @endforeach
                                                            </select>
                                                        </div>
                                                    </div>
                                                    @if($subscription_id == 'course')
                                                        <div class="mt-4">
                                                            <div class="col-12 mt-2">
                                                                <label for="course_name" class="form-label">Tipo corso</label><br>
                                                                <label class="form-radio-wrapper"><input type="radio" name="chkType" value="standard" wire:model="course_course_type">Singolo</label>
                                                                <label class="form-radio-wrapper"><input type="radio" name="chkType" value="custom" wire:model="course_course_type">Personalizzato</label>
                                                            </div>
                                                            <div class="row mt-3">
                                                                <div class="col-md-4">
                                                                    <label for="course_name" class="form-label">Corso</label>
                                                                    <select id="course_name" class="form-select" aria-label="Livello" wire:model="course_name" >
                                                                        <option value="">
                                                                        @foreach($course_names as $key => $value)
                                                                            <option value="{{$key}}">{{$value}}
                                                                        @endforeach
                                                                    </select>
                                                                </div>
                                                                @error('course_course_id')
                                                                    <div class="invalid-feedback">Devi selezionare un corso</div>
                                                                @enderror
                                                                @if($course_exist)
                                                                    <small style="color:red">Attenzione : il corso selezionato è già associato all'utente</small>
                                                                @endif
                                                                @if($course_name != '')
                                                                    <div class="col-md-4">
                                                                        <label for="course_level_id" class="form-label">Livello</label>
                                                                        <select id="course_level_id" class="form-select" aria-label="Livello" wire:model="course_level_id" >
                                                                            <option value="">
                                                                            @foreach($course_levels as $l)
                                                                                <option value="{{$l->id}}">{{$l->name}}
                                                                            @endforeach
                                                                        </select>
                                                                    </div>
                                                                @endif
                                                                @if($course_level_id != '')
                                                                    <div class="col-md-4">
                                                                        <label for="course_frequency_id" class="form-label">Frequenza</label>
                                                                        <select id="course_frequency_id" class="form-select" aria-label="Tipologia" wire:model="course_frequency_id" >
                                                                            <option value="">
                                                                            @foreach($course_frequencies as $f)
                                                                                <option value="{{$f->id}}">{{$f->name}}
                                                                            @endforeach
                                                                        </select>
                                                                    </div>
                                                                @endif
                                                            </div>
                                                        </div>
                                                        @if($course_course_id > 0)
                                                            <div class="row mt-4">
                                                                <div class="col-md-6">
                                                                    <label for="course_course_subscription_id" class="form-label">Pagamenti</label>
                                                                    <select id="course_course_subscription_id" class="form-select  @error('course_course_subscription_id') is-invalid @enderror" aria-label="Pagamenti" wire:model="course_course_subscription_id">
                                                                        <option value="">
                                                                        @foreach($course_subscriptions as $t)
                                                                            <option value="{{$t["id"]}}">{{$t["name"]}}
                                                                        @endforeach
                                                                    </select>
                                                                </div>
                                                                <div class="col-md-6">
                                                                    <label for="course_price" class="form-label">Costo</label>
                                                                    <input class="form-control" type="text" id="course_price" placeholder="Costo" wire:model="course_price" onkeyup="onlyNumberAmount(this)">
                                                                </div>
                                                            </div>
                                                            @if(false)
                                                                <div class="row mt-4 course--duration">
                                                                    <div class="col-md-12">
                                                                        <label for="duration" class="form-label">Durata del corso</label>
                                                                        <div class="d-flex course--duration_mounth">
                                                                            @foreach($course_months_list as $cm)
                                                                                <a class="{{$this->checkMonth($cm) ? 'selected' : 'notSelected'}}" wire:click="setMonth({{$cm}})">{{getMonthName($cm, true)}}</a>
                                                                            @endforeach
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                            @endif
                                                            <div class="row mt-4">
                                                                <div class="col-md-6">
                                                                    <label for="course_date_from" class="form-label">Data inizio</label>
                                                                    <input class="form-control" type="date" id="course_date_from" wire:model="course_date_from">
                                                                </div>
                                                                <div class="col-md-6">
                                                                    <label for="course_date_to" class="form-label">Data fine</label>
                                                                    <input class="form-control" type="date" id="course_date_to" wire:model="course_date_to">
                                                                </div>
                                                            </div>
                                                            <div class="row mt-4">
                                                                <div class="col-md-6">
                                                                    <label for="course_subscription_price" class="form-label">Costo iscrizione</label>
                                                                    <input class="form-control" type="text" id="course_subscription_price" placeholder="Costo iscrizione" wire:model="course_subscription_price" onkeyup="onlyNumberAmount(this)">
                                                                </div>
                                                            </div>
                                                            @if($course_course_type == 'custom')
                                                                @foreach($course_when as $idW => $when)
                                                                    <div class="row">
                                                                        <div class="col-12">
                                                                            <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', $course_when[$idW]["day"]) ? 'selected' : 'notSelected'}}" wire:click="setDay({{$idW}}, 'lun')">Lun</a>
                                                                                    <a class="{{in_array('mar', $course_when[$idW]["day"]) ? 'selected' : 'notSelected'}}" wire:click="setDay({{$idW}}, 'mar')">Mar</a>
                                                                                    <a class="{{in_array('mer', $course_when[$idW]["day"]) ? 'selected' : 'notSelected'}}" wire:click="setDay({{$idW}}, 'mer')">Mer</a>
                                                                                    <a class="{{in_array('gio', $course_when[$idW]["day"]) ? 'selected' : 'notSelected'}}" wire:click="setDay({{$idW}}, 'gio')">Gio</a>
                                                                                    <a class="{{in_array('ven', $course_when[$idW]["day"]) ? 'selected' : 'notSelected'}}" wire:click="setDay({{$idW}}, 'ven')">Ven</a>
                                                                                    <a class="{{in_array('sab', $course_when[$idW]["day"]) ? 'selected' : 'notSelected'}}" wire:click="setDay({{$idW}}, 'sab')">Sab</a>
                                                                                    <a class="{{in_array('dom', $course_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="course_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="course_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>
                                                                    </div>
                                                                @endforeach
                                                            @endif
                                                            <div class="row  mt-2">
                                                                <div class="col-md-12">
                                                                    <label for="course_date_from" class="form-label">Note</label>
                                                                    <input class="form-control" type="text" id="course_note" placeholder="Note" wire:model="course_note">
                                                                </div>
                                                            </div>
                                                        @endif
                                                    @elseif($subscription_id != '')
                                                        <div class="row mt-4">
                                                            <div class="col-md-6">
                                                                <label for="subscription_course_subscription_id" class="form-label">Pagamenti</label>
                                                                <select id="subscription_course_subscription_id" class="form-select  @error('subscription_course_subscription_id') is-invalid @enderror" aria-label="Pagamenti" wire:model="subscription_course_subscription_id">
                                                                    <option value="">
                                                                    @foreach($subscription_subscriptions as $t)
                                                                        <option value="{{$t["id"]}}">{{$t["name"]}}
                                                                    @endforeach
                                                                </select>
                                                            </div>
                                                            <div class="col-md-6">
                                                                <label for="subscription_price" class="form-label">Costo</label>
                                                                <input class="form-control" type="text" id="subscription_price" placeholder="Costo" wire:model="subscription_price" onkeyup="onlyNumberAmount(this)">
                                                            </div>
                                                        </div>
                                                        <div class="row mt-4">
                                                            <div class="col-md-6">
                                                                <label for="subscription_date_from" class="form-label">Data inizio</label>
                                                                <input class="form-control" type="date" id="subscription_date_from" wire:model="subscription_date_from">
                                                            </div>
                                                            <div class="col-md-6">
                                                                <label for="subscription_date_to" class="form-label">Data fine</label>
                                                                <input class="form-control" type="date" id="subscription_date_to" wire:model="subscription_date_to">
                                                            </div>
                                                        </div>
                                                        <div class="row mt-4">
                                                            <div class="col-md-6">
                                                                <label for="subscription_subscription_price" class="form-label">Costo iscrizione</label>
                                                                <input class="form-control" type="text" id="subscription_subscription_price" placeholder="Costo iscrizione" wire:model="subscription_subscription_price" onkeyup="onlyNumberAmount(this)">
                                                            </div>
                                                        </div>
                                                        <div class="row mt-4">
                                                            <div class="col-md-12">
                                                                <label for="subscription_notes" class="form-label">Note</label>
                                                                <input class="form-control" type="text" id="subscription_notes" placeholder="Note" wire:model="subscription_notes">
                                                            </div>
                                                        </div>
                                                    @endif
                                                </form>
                                            </div>

                                            <br>
                                            <div class="row mt-5">
                                                <div class="col-md-12">
                                                    <button class="btn--ui lightGrey" wire:click.prevent="cancelCourse()">Annulla</button>

                                                    @if($course_course_id > 0)
                                                        @if($addCourse)
                                                            @if(!$course_exist)
                                                                <button class="btn--ui primary" wire:click.prevent="storeCourse()">Salva corso</button>
                                                            @endif
                                                        @endif
                                                        @if($updateCourse)
                                                            <button class="btn--ui primary" wire:click.prevent="updateCourse()">Salva corso</button>
                                                        @endif
                                                    @endif

                                                    @if($subscription_id > 0 && $subscription_id != 'course')
                                                        @if($addCourse)
                                                            @if(!$subscription_exist)
                                                                <button class="btn--ui primary" wire:click.prevent="storeSubscription()">Salva abbonamento</button>
                                                            @endif
                                                        @endif
                                                        @if($updateCourse)
                                                            <button class="btn--ui primary" wire:click.prevent="updateSubscription()">Salva abbonamento</button>
                                                        @endif
                                                    @endif
                                                </div>
                                            </div>
                                        @endif
                                    @endif
                                @endif
                            </div>
                        </div>
                        <div class="col-md-5 col-xl-4 p-3">
                            <div id="card--resume" class="primary card--ui ms-3 user--resume">
                                <header>
                                    <div class="username d-flex align-items-start">
                                        {{-- <i class="ico--ui utenti light me-2"></i> --}}
                                        <div class="user--resume_name d-flex flex-column">
                                            <span class="user-name">{{ strtoupper($first_name) }} {{ strtoupper($last_name) }}</span>
                                            
                                            @if($dataId > 0)
                                            <div class="user_name me-4">
                                                <span class="badge tessera-badge {{$active["status"] > 0 ? ($active["status"] == 2 ? 'active' : 'due') : 'suspended'}}">{{$active["status"] > 0 ? ($active["status"] == 2 ? 'Tesserato' : 'Sospeso') : 'Non tesserato'}}</span>
                                            </div>
                                            @endif

                                            {{-- <span class="user-email">{{ $birth_date ? date("d/m/Y", strtotime($birth_date)) : '' }}{!!$age != '' ? ' (' . $age . ')' : ''!!}</span> --}}
                                        </div>
                                    </div>
                                </header>
                                <div class="card--resume_body">
                                    <ul class="user-address mb-4 p-0">
                                        <li><i class="fa-solid fa-phone"></i><span>Tel. {{ $phone }}</span></li>
                                        <li><i class="fa-solid fa-calendar"></i><span>Nato il {{ $birth_date ? date("d/m/Y", strtotime($birth_date)) : '' }}{!!$age != '' ? ' (' . $age . ')' : ''!!}</span></li>
                                        <li><i class="fa-solid fa-envelope"></i><span>{{ $email }}</span></li>
                                    </ul>
                                    <ul class="user-residence p-0">
                                        <li>
                                            <i class="fa-solid fa-building"></i>
                                            {{-- <i class="ico--ui resume--ico residence me-2"></i> --}}
                                            <span>
                                                @if($city_id > 0)
                                                    {{$this->getCity($city_id)}}
                                                    @if($province_id > 0)
                                                        ( {{$this->getProvince($province_id)}} ) -
                                                    @endif
                                                @endif
                                                {{ $zip_code }}<br>
                                                {{ $address }}
                                            </span>
                                        </li>
                                    </ul>
                                    <div class="resume--tab_info tesseramento">
                                        <h2 class="mb-3"><i class="fa-solid fa-file-lines"></i><span>Certificato</span></h2>
                                        @if(sizeof($member_certificates) > 0)
                                            @php
                                                $cert = $member_certificates[0];
                                                
                                                $fileService = app(App\Services\MemberFileService::class);
                                                $certificateUrl = "#";
                                                if($cert->filename != '') {
                                                    $certificateUrl = $fileService->getFileUrl($cert->filename);
                                                }
                                            @endphp
                                            <div class="resume--wrapper d-flex align-items-start justify-content-between mb-2">
                                                <div class="resume--info resume-certificato d-flex align-items-start">
                                                    {{-- <i class="fa-regular fa-file-lines me-2"></i> --}}
                                                    <div class="title--tessera_added">
                                                        <h4>{{$cert->type == 'A' ? 'Agonistico' : 'Non agonistico'}}</h4>
                                                        <span class="title-detail">Scadenza: <span class="title-detail_date">{{$cert->expire_date ? date("d/m/Y", strtotime($cert->expire_date)) : ''}}</span></span></small>
                                                    </div>
                                                </div>
                                                @if($cert->expire_date . " 23:59:59" < date("Y-m-d"))
                                                    <span class="badge tessera-badge suspended">scaduto</span>
                                                @endif
                                                @if($cert->expire_date . " 23:59:59" >= date("Y-m-d") && $cert->expire_date < date("Y-m-d", strtotime("+1 month")))
                                                    <span class="badge tessera-badge due">in scadenza</span>
                                                @endif
                                                @if($cert->expire_date . " 23:59:59" >= date("Y-m-d", strtotime("+1 month")))
                                                    <span class="badge tessera-badge active">valido</span>
                                                @endif
                                            </div>
                                        @endif
                                    </div>
                                    <div class="resume--tab_info tesseramento">
                                        <h2 class="mb-3"><i class="fa-solid fa-address-card"></i><span>Tesseramento</span></h2>
                                        @foreach($member_cards as $member_card)
                                            @if($member_card->expire_date . " 23:59:59" > date("Y-m-d"))
                                                <div class="resume--wrapper d-flex align-items-start justify-content-between mb-2">
                                                    <div class="resume--info resume-tessera d-flex align-items-start">
                                                        {{-- <i class="ico--ui tessera me-2"></i> --}}
                                                        <div class="title--tessera_added">
                                                            <h4>{{$member_card->card->name}}</h4>
                                                            <span class="title-detail">Scadenza: <span class="title-detail_date">{{$member_card->expire_date ? date("d/m/Y", strtotime($member_card->expire_date)) : ''}}</span></span></small>
                                                            @if($member_card->discipline_1)
                                                            </br>
                                                                <span class="title-detail">Disciplina : <b>{{$member_card->discipline_1->name}}</b></span>
                                                            @endif
                                                            @if($member_card->discipline_2)
                                                            </br>
                                                                <span class="title-detail">Disciplina : <b>{{$member_card->discipline_2->name}}</b></span>
                                                            @endif
                                                            @if($member_card->discipline_3)
                                                            </br>
                                                                <span class="title-detail">Disciplina : <b>{{$member_card->discipline_3->name}}</b></span>
                                                            @endif
                                                        </div>
                                                    </div>
                                                    <span class="badge tessera-badge active">attiva</span>
                                                </div>
                                            @endif
                                        @endforeach
                                    </div>
                                    <div class="resume--tab_info gruppi corsi">
                                        <h2 class="mb-3"><i class="fa-solid fa-chalkboard"></i><span>Corsi e Abbonamenti</span></h2>
                                        @foreach($member_subscriptions as $member_subscription)
                                            <div class="resume--info resume-corso d-flex align-items-center">
                                                <div class="row">
                                                    <div class="row">
                                                        <strong>{{$member_subscription->subscription->name}}</strong>
                                                    </div>
                                                    <div class="row">
                                                        <span class="title-detail">
                                                            {{date('d/m/Y', strtotime($member_subscription->date_from))}} - {{date('d/m/Y', strtotime($member_subscription->date_to))}}
                                                            {{-- @if($member_subscription->notes != '')
                                                                <b>Note: </b>
                                                                {{$member_subscription->notes}}
                                                            @endif --}}
                                                        </span>
                                                    </div>
                                                </div>
                                            </div>
                                        @endforeach
                                        @foreach($member_courses as $member_course)
                                            @php
                                                $course_year = date('Y', strtotime($member_course->date_from));
                                                $current_year = date('Y');
                                                $course_month = date('m', strtotime($member_course->date_from));
                                                $current_month = date('m');
                                            @endphp
                                            @if (
                                                ($course_year == (date('Y') + 1) && $course_month <=8) ||
                                                ($course_year == date('Y') && $course_month >= 9)
                                            )
                                                <div class="resume--info resume-corso d-flex align-items-center">
                                                    <div class="row">
                                                        <div class="row">
                                                            <strong>{{$member_course->course->getTree()}}</strong>
                                                        </div>
                                                        <div class="row">
                                                            <span class="title-detail">
                                                                {{$member_course->course->level->name ?? ""}}<br>
                                                                {{$member_course->course->frequency->name ?? ""}}
                                                            </span>
                                                        </div>
                                                        <div class="row">
                                                            <span class="title-detail">
                                                                @php
                                                                    $ok = false;
                                                                @endphp
                                                                @foreach(json_decode($member_course->when) as $xx => $x)
                                                                    @if($xx > 0)
                                                                        <br>
                                                                    @endif
                                                                    @foreach($x->day as $zz => $d)
                                                                        {{$zz > 0 ? '-' : ''}}{{$d}}
                                                                    @endforeach
                                                                    @if($x->from != '' && $x->to != '')
                                                                        h {{$x->from}} - {{$x->to}}
                                                                    @endif
                                                                    @php
                                                                        $ok = $x->from != '';
                                                                    @endphp
                                                                @endforeach
                                                                @if(!$ok && $member_course->course->when != '')
                                                                    @foreach(json_decode($member_course->course->when) as $xx => $x)
                                                                        @php
                                                                            $ok = true;
                                                                        @endphp
                                                                        @if($xx > 0)
                                                                            <br>
                                                                        @endif
                                                                        @foreach($x->day as $zz => $d)
                                                                            {{$zz > 0 ? '-' : ''}}{{$d}}
                                                                        @endforeach
                                                                        @if($x->from != '')
                                                                            h {{$x->from}} - {{$x->to}}
                                                                        @endif
                                                                    @endforeach
                                                                @endif
                                                            </span>
                                                        </div>
                                                    </div>
                                                </div>
                                            @endif
                                        @endforeach
                                    </div>
                                    <div class="resume--tab_info gruppi">
                                        <h2 class="mb-3"><i class="fa-solid fa-users"></i><span>Gruppi di interesse</span></h2>
                                        <ul>
                                        @foreach($member_categories as $member_category)
                                            <li class="resume--info"><span>{{$member_category->category->getTree()}}</span></li>
                                        @endforeach
                                        </ul>
                                    </div>
                                    <div class="resume--tab_info credito">
                                        <h2 class="mb-3"><i class="fa-solid fa-wallet"></i><span>Borsellino MAD</span></h2>
                                        <span class="value">{{formatPrice($money)}}</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                @if (!$addCard && !$updateCard && !$addCourse && !$updateCourse)
                    <section class="save--section d-flex justify-content-start">
                        <div class="container">
                            <div class="row">
                                <div class="col-md-7 col-xl-8 d-flex gx-0">
                                    @if($add)
                                        <button class="btn--ui primary d-flex order-1 me-2" wire:click="store(false)">salva e continua</button>
                                        <button class="btn--ui primary d-flex order-3 ms-auto" onclick="store(true)">salva e chiudi</button>
                                    @endif
                                    @if($update)
                                        <button class="btn--ui primary d-flex order-1 me-2" wire:click="updateAAA(false)">salva e continua</button>
                                        <button class="btn--ui primary d-flex order-3 ms-auto" onclick="updateAAA(true)">salva e chiudi</button>
                                    @endif
                                    <button class="btn--ui lightGrey" onclick="annulla()" style="margin-right:10px">annulla</button><br><br>
                                </div>
                                <div class="col-md-5 col-xl-4"></div>
                            </div>
                        </div>
                    </section>
                @endif
            @endif
        </div>
    @endif
        <div  wire:ignore.self class="modal fade" id="userModal" tabindex="-1" aria-labelledby="userModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                <div class="modal-header modal-header-blu">
                    <h5 class="modal-title" id="userModalLabel">Modifica borsellino</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <div class="row">
                        <div class="col-md-6">
                            <label for="newMemberFirstName" class="form-label">Importo</label>
                            <input class="form-control " type="text" id="importoBorsellino" >
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn--ui lightGrey" data-bs-dismiss="modal">Annulla</button>
                    <button type="button" class="btn--ui btn-primary" onclick="updateBorsellino('-')">Decrementa</button>
                    <button type="button" class="btn--ui btn-primary" onclick="updateBorsellino('+')">Aumenta</button>
                </div>
                </div>
            </div>
        </div>
</div>
@push('scripts')
    <link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
    <style>
        table.tableHead thead
        {
            position: sticky;
            z-index: 100;
            top: 0;
        }
        .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;
        }
        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;
        }
        .btn--ui.lightGrey, .btn--ui.extraLightGrey
        {
            -webkit-border-radius: 0.5rem !important;
            background-color:#ffffff !important;
            border: 1px solid grey;
            color: black;
            font-weight:normal;
        }

        .persistent-invalid
        {
            border-color: #dc3545 !important;
            padding-right: calc(1.5em + 0.75rem) !important;
            background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' width='12' height='12' fill='none' stroke='%23dc3545'%3e%3ccircle cx='6' cy='6' r='4.5'/%3e%3cpath stroke-linejoin='round' d='M5.8 3.6h.4L6 6.5z'/%3e%3ccircle cx='6' cy='8.2' r='.6' fill='%23dc3545' stroke='none'/%3e%3c/svg%3e") !important;
            background-repeat: no-repeat !important;
            background-position: right calc(0.375em + 0.1875rem) center !important;
            background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem) !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="https://cdn.jsdelivr.net/npm/chart.js"></script>
@endpush

@push('scripts')
    <script>
        function matchStart(params, data) {
            params.term = params.term || '';
            if (data.text.toUpperCase().indexOf(params.term.toUpperCase()) == 0) {
                return data;
            }
            return false;
        }
        var nation_id = {{$nation_id > 0 ? $nation_id : 0}};
        var province_id = 0;
        var nation_birth_id = 0;
        var province_birth_id = 0;

        Livewire.on('load-select', () => {

            loadCombo();

        });

        function updateBorsellino(verse)
        {
            var importoBorsellino = $("#importoBorsellino").val();
            @this.updateBorsellino(importoBorsellino, verse);
        }

        Livewire.on('load-provinces', (nation_id, element) => {
            $('.' + element).select2({
                ajax: {
                    url: '/provinces/' + nation_id,
                    dataType: 'json'
                }
            });
        });

        Livewire.on('load-cities', (province_id, element) => {
            $('.' + element).select2({
                ajax: {
                    url: '/cities/' + province_id,
                    dataType: 'json'
                }
            });
        });

        Livewire.on('hide-search', () => {
            //pcsh2();
        });

        Livewire.on('setIds', (nation_id_x, birth_nation_id_x) => {
            nation_id = nation_id_x;
            nation_birth_id = birth_nation_id_x;
        });

        function loadCombo()
        {
            $('.nationClass').select2({
                ajax: {
                    url: '/nations',
                    dataType: 'json'
                }
            });

            $('.nationClass').on('change', function (e) {
                nation_id = $('.nationClass').select2("val");
                province_id = 0;
                @this.set('nation_id', nation_id);
                @this.set('province_id', 0);
                @this.set('city_id', 0);
                @this.checkIsItaly();
            });

            $('.provinceClass').select2({
                ajax: {
                    url: '/provinces/' + nation_id,
                    dataType: 'json'
                }
            });
            $('.provinceClass').on('change', function (e) {
                province_id = $('.provinceClass').select2("val");
                @this.set('province_id', province_id);
                @this.set('city_id', 0);
            });

            $('.cityClass').select2({
                ajax: {
                    url: '/cities/' + province_id,
                    dataType: 'json'
                }
            });
            $('.cityClass').on('change', function (e) {
                var data = $('.cityClass').select2("val");
                @this.set('city_id', data);

            });

            $('.nationBirthClass').select2({
                ajax: {
                    url: '/nations',
                    dataType: 'json'
                }
            });

            $('.nationBirthClass').on('change', function (e) {
                nation_birth_id = $('.nationBirthClass').select2("val");
                province_birth_id = 0;
                @this.set('birth_nation_id', nation_birth_id);
                @this.set('birth_province_id', 0);
                @this.set('birth_city_id', 0);
                @this.checkIsBirthItaly();
            });

            $('.provinceBirthClass').select2({
                ajax: {
                    url: '/provinces/' + nation_birth_id,
                    dataType: 'json'
                }
            });
            $('.provinceBirthClass').on('change', function (e) {
                province_birth_id = $('.provinceBirthClass').select2("val");
                @this.set('birth_province_id', province_birth_id);
                @this.set('birth_city_id', 0);
            });

            $('.cityBirthClass').select2({
                ajax: {
                    url: '/cities/' + province_birth_id,
                    dataType: 'json'
                }
            });
            $('.cityBirthClass').on('change', function (e) {
                var data = $('.cityBirthClass').select2("val");
                @this.set('birth_city_id', data);

            });


            $('.card_card_id').select2({
                    matcher: function(params, data) {
                        return matchStart(params, data);
                    }
                });
            $('.card_card_id').on('change', function (e) {
                var data = $('.card_card_id').select2("val");
                @this.set('card_card_id', data);
            });

            $('.certificate_type').select2({
                    matcher: function(params, data) {
                        return matchStart(params, data);
                    }
                });
            $('.certificate_type').on('change', function (e) {
                var data = $('.certificate_type').select2("val");
                @this.set('certificate_type', data);
            });

            $('.categoriesClass').select2({
                    matcher: function(params, data) {
                        return matchStart(params, data);
                    }
                });
            $('.categoriesClass').on('change', function (e) {
                var data = $('.categoriesClass').select2("val");
                @this.set('category_category_id', data);
            });

            $('.coursesClass').select2({
                    matcher: function(params, data) {
                        return matchStart(params, data);
                    }
                });
            $('.coursesClass').on('change', function (e) {
                var data = $('.coursesClass').select2("val");
                @this.set('course_course_id', data);
            });
        }

        @if($refreshAfter == 1)
            setTimeout(() => {
                loadCombo();
            }, 100)
        @endif

        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.');
        }

    </script>

@endpush

@push('scripts')
    <link href="/css/datatables.css" rel="stylesheet" />
    <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>

        window.addEventListener("scroll-to-top", (e) => {
            let container = document.getElementById("card--dashboard");
            if (container) {
                container.scrollTo(0,0);
            }
        });

        Livewire.on('saved-and-continue', (currentTab) => {
            const nextTab = getNextTab(currentTab);
            if (nextTab !== currentTab) {
                @this.change(nextTab);
            }
        });

        function getNextTab(currentTab) {
            const tabs = ['dati', 'tesseramento', 'corsi', 'presenze', 'gruppi'];
            const currentIndex = tabs.indexOf(currentTab);
            return currentIndex < tabs.length - 1 ? tabs[currentIndex + 1] : currentTab;
        }

        function showData(id)
        {
            @this.showDetailF(id);
        }

        function editData(id) {
            if ($('#tablesaw-350').length && $.fn.DataTable.isDataTable('#tablesaw-350')) {
                const dataTable = $('#tablesaw-350').DataTable();
                const pageLength = dataTable.page.len();
                const currentPage = dataTable.page.info().page;
                const order = dataTable.order();


                if (order && order.length > 0) {
                    localStorage.setItem('dtOrderColumn', order[0][0]);
                    localStorage.setItem('dtOrderDir', order[0][1]);
                }
            }

            window.scrollTo({
                top: 0,
                behavior: 'smooth'
            });

            @this.edit(id);
        }

        function deleteData(id)
        {
            if (confirm('Sei sicuro?'))
                @this.delete(id);
        }

        function archiveData(id)
        {
            if (confirm('Sei sicuro? L\'utente non sarà più visibile ma potrà essere ripristinato dalla sezione Archivio.'))
                @this.archive(id);
        }

        var isFilter = false;
        $(document).ready(function() {
            isFilter = Number(localStorage.getItem("isFilter_Member")) ?? 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_Member", Number(isFilter));
            });
        } );

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

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

        });

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

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

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

        function loadFilters() {
            let show = false;
            var filterStatus = localStorage.getItem("filterStatusMember");
            if (filterStatus != null && filterStatus != "null" && filterStatus != "undefined" && filterStatus)
            {
                $('.filterStatus').val(filterStatus).trigger('change');
                show = true;
            }
            var filterCards = localStorage.getItem("filterCardsMember");
            if (filterCards != null && filterCards != "null" && filterCards != "undefined" && filterCards)
            {
                $('.filterCards').val(filterCards).trigger('change');
                show = true;
            }
            var filterScadenza = localStorage.getItem("filterScadenzaMember");
            if (filterScadenza != null && filterScadenza != "null" && filterScadenza != "undefined" && filterScadenza)
            {
                $('.filterScadenza').val(filterScadenza).trigger('change');
                show = true;
            }
            var filterCertificateType = localStorage.getItem("filterCertificateTypeMember");
            if (filterCertificateType != null && filterCertificateType != "null" && filterCertificateType != "undefined" && filterCertificateType)
            {
                $('.filterCertificateType').val(filterCertificateType).trigger('change');
                show = true;
            }
            var filterCategories = localStorage.getItem("filterCategoriesMember");
            if (filterCategories != null && filterCategories != "null" && filterCategories != "undefined" && filterCategories)
            {
                $('.filterCategories').val(filterCategories).trigger('change');
                show = true;
            }
            var fromYear = localStorage.getItem("fromYearMember");
            if (fromYear != null && fromYear != "null" && fromYear != "undefined" && fromYear)
            {
                $('input[name="txtFromYear"]').val(fromYear);
                show = true;
            }
            var toYear = localStorage.getItem("toYearMember");
            if (toYear != null && toYear != "null" && toYear != "undefined" && toYear)
            {
                $('input[name="txtToYear"]').val(toYear);
                show = true;
            }
            var fromYearYear = localStorage.getItem("fromYearYearMember");
            if (fromYearYear != null && fromYearYear != "null" && fromYearYear != "undefined" && fromYearYear)
            {
                $('input[name="txtFromYearYear"]').val(fromYearYear);
                show = true;
            }

            var toYearYear = localStorage.getItem("toYearYearMember");
            if (toYearYear != null && toYearYear != "null" && toYearYear != "undefined" && toYearYear)
            {
                $('input[name="txtToYearYear"]').val(toYearYear);
                show = true;
            }

            if (show) {
                $('.showFilter').show();
            }
        }

        var filterStatus = localStorage.getItem("filterStatusMember");
        if (filterStatus)
        {
            $('.filterStatus').val(filterStatus).trigger('change');
        }
        var filterCards = localStorage.getItem("filterCardsMember");
        if (filterCards)
        {
            $('.filterCards').val(filterCards).trigger('change');
        }
        var filterScadenza = localStorage.getItem("filterScadenzaMember");
        if (filterScadenza)
        {
            $('.filterScadenza').val(filterScadenza).trigger('change');
        }
        var filterCertificateType = localStorage.getItem("filterCertificateTypeMember");
        if (filterCertificateType)
        {
            $('.filterCertificateType').val(filterCertificateType).trigger('change');
        }
        var filterCategories = localStorage.getItem("filterCategoriesMember");
        if (filterCategories)
        {
            $('.filterCategories').val(filterCategories).trigger('change');
        }
        var fromYear = localStorage.getItem("fromYearMember");
        if (fromYear)
        {
            $('input[name="txtFromYear"]').val(fromYear);
        }
        var toYear = localStorage.getItem("toYearMember");
        if (toYear)
        {
            $('input[name="txtToYear"]').val(toYear);
        }
        var fromYearYear = localStorage.getItem("fromYearYearMember");
        if (fromYearYear)
        {
            $('input[name="txtFromYearYear"]').val(fromYearYear);
        }
        var toYearYear = localStorage.getItem("toYearYearMember");
        if (toYearYear)
        {
            $('input[name="txtToYearYear"]').val(toYearYear);
        }

        $(document).on("keypress", $('.filterCategories'), function (e) {

            setTimeout(() => {
                $(".select2-results__option").each(function(){
                    var txt = $(this).html();
                    var count = (txt.match(/-/g) || []).length;
                    $(this).addClass('paddingLeftSelect' + count);
                });
            }, 100);
        });

        $('.filterCategories').on('select2:open', function (e) {
            setTimeout(() => {
                $(".select2-results__option").each(function(){
                    var txt = $(this).html();
                    var count = (txt.match(/-/g) || []).length;
                    $(this).addClass('paddingLeftSelect' + count);
                });
            }, 100);
        });

        function reset()
        {
            $('.filterCards').val('').trigger('change');
            $('.filterStatus').val('').trigger('change');
            $('.filterScadenza').val('-1').trigger('change');
            $('.filterCertificateType').val('-1').trigger('change');
            $('.filterCategories').val('-1').trigger('change');


            $('input[name="txtFromYear"]').val('');
            $('input[name="txtToYear"]').val('');

            $('input[name="txtFromYearYear"]').val('');
            $('input[name="txtToYearYear"]').val('');
            loadDataTable();
        }


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

            const url = '/get_members?cards=' + $('.filterCards').val() + "&filterCategories=" + $('.filterCategories').val() + "&filterCertificateType=" + $('.filterCertificateType').val() + "&filterScadenza=" + $('.filterScadenza').val() + "&filterStatus=" + $('.filterStatus').val() + "&fromYear=" + $('input[name="txtFromYear"]').val() + "&toYear=" + $('input[name="txtToYear"]').val() + "&fromYearYear=" + $('input[name="txtFromYearYear"]').val() + "&toYearYear=" + $('input[name="txtToYearYear"]').val();

            localStorage.setItem("filterCardsMember", $('.filterCards').val());
            localStorage.setItem("filterCategoriesMember", $('.filterCategories').val());
            localStorage.setItem("filterCertificateTypeMember", $('.filterCertificateType').val());
            localStorage.setItem("filterScadenzaMember", $('.filterScadenza').val());
            localStorage.setItem("filterStatusMember", $('.filterStatus').val());
            localStorage.setItem("fromYearMember", $('input[name="txtFromYear"]').val());
            localStorage.setItem("toYearMember", $('input[name="txtToYear"]').val());
            localStorage.setItem("fromYearYearMember", $('input[name="txtFromYearYear"]').val());
            localStorage.setItem("toYearYearMember", $('input[name="txtToYearYear"]').val());

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

            const pageLength = 10;

            const dataTable = $('#tablesaw-350').DataTable({
                serverSide: true,
                processing: true,
                stateSave: true,
                ajax: url,
                columns: [
                    {
                        data: "last_name",
                        render: function (data){
                            const d = data.split("|");
                            var ret = '<a style="cursor:pointer" onclick="showData(' + d[1] + ')">' + d[0] + '</a>';
                            return ret;
                        }
                    },
                    {
                        data: "first_name",
                        render: function (data){
                            const d = data.split("|");
                            var ret = '<a style="cursor:pointer" onclick="showData(' + d[1] + ')">' + d[0] + '</a>';
                            return ret;
                        }
                    },
                    { data: "phone"},
                    { data: "age", "type": "num", className:"dt-type-numeric"},
                    { data: "year", className:"dt-type-numeric"},
                    {
                        data: "status",
                        render: function (data){
                            const d = data.split("|");
                            var ret = '<span class="tablesaw-cell-content"><span class="badge tessera-badge ' + d[0] + '">' + d[1] + '</span></span>';
                            return ret;
                        }
                    },
                    {
                        data: "certificate",
                        render: function (data){
                            var ret = '';
                            if (data != "") {
                                const d = data.split("|");
                                ret += '<span class="tablesaw-cell-content d-flex align-items-center">';
                                if (d[0] == "0") {
                                    ret += '<i class="ico--ui check suspended me-2"></i>';
                                    ret += 'Scaduto : ';
                                }
                                if (d[0] == "1") {
                                    ret += '<i class="ico--ui check due me-2"></i>';
                                    ret += 'In scadenza: ';
                                }
                                if (d[0] == "2") {
                                    ret += '<i class="ico--ui check active me-2"></i>';
                                    ret += 'Scadenza: ';
                                }
                                ret += d[1];
                                ret += '</span>';
                            }
                            if(data == ""){
                                ret += '<span class="tablesaw-cell-content d-flex align-items-center">';
                                ret += '<i class="ico--ui check absent me-2"></i>';
                                ret += 'Non consegnato';
                                ret += '</span>';
                            }
                            return ret;
                        }
                    },
                    {
                        data: "action",
                        render: function (data){
                            var ret = '<button type="button" class="btn" onclick="editData(' + data + ')" 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>&nbsp;';
                            ret += '<button type="button" class="btn" onclick="archiveData(' + data + ')" data-bs-toggle="popover" data-bs-trigger="hover focus" data-bs-placement="bottom" data-bs-content="Archivia"><i class="fa-regular fa-folder-closed"></i></button>';
                            return ret;
                        }
                    },
                ],
                fixedHeader: false,
                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 + 'Utenti',
                                        filename: date_export + 'Utenti',
                                        exportOptions: {
                                            columns: ":not(':last')",
                                            page: 'all'
                                        }
                                    },
                                    {
                                        extend: 'pdfHtml5',
                                        text: '<i class="fa-solid fa-file-pdf"></i>',
                                        action: newexportaction,
                                        title: date_export + 'Utenti',
                                        filename: date_export + 'Utenti',
                                        exportOptions: {
                                            columns: ":not(':last')"
                                        },
                                        customize: function(doc) {
                                            doc.styles.tableHeader.alignment = 'left';
                                        }
                                    },
                                    {
                                        extend: 'print',
                                        action: newexportaction,
                                        text: '<i class="fa-solid fa-print"></i>',
                                        title: date_export + 'Utenti',
                                        filename: date_export + 'Utenti',
                                        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
                        }
                    }
                },
                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 style="cursor:pointer" class="showHideFilter btn--ui"><i class="fa-solid fa-sliders"></i></a>';
                    html += '&nbsp;<a style="cursor:pointer" class="addData btn--ui"><i class="fa-solid fa-plus"></i></a>';
                    $(".dt-search").append(html);
                    
                    loadFilters();
                }
            });

            $('#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()
            });
        }

        $(document).ready(function() {
            $(document).on("click",".addData",function() {
                $(".title--section_addButton").trigger("click")
            });
        } );

        var isEdit = false;
        var isEditCorso = false;

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

        Livewire.on('setEditCorso', (x) =>
        {
            isEditCorso = x;
            console.log("Edit corso" + isEditCorso);
        });

        Livewire.on('setErrorMsg', (errors) =>
        {

            function msg(value)
            {
                const myArray = value.split("=");
                if (myArray[1] == '0' || myArray[1] == '')
                    $("span").find("[aria-controls='select2-" + myArray[0] + "-container']").css('border', 'solid 3px #dc3545');
            }
            console.log(errors);

        });

        Livewire.on('reload', (x) =>
        {
            location.reload();
        });

        Livewire.on('goToTop', () => {
            @this.set('type', 'dati');
            document.body.scrollTop = document.documentElement.scrollTop = 0;
        });

        function storeAction(type)
        {
            @this.change('dati');
            if (isEditCorso)
            {
                if (confirm('Non hai concluso l\' inserimento/modifica del corso, vuoi comunque procedere?'))
                    @this.store(type);
            }
            else
            {
                document.body.scrollTop = document.documentElement.scrollTop = 0;
            }
        }

        function updateAction(type)
        {
            @this.change('dati');
            if (isEditCorso)
            {
                if (confirm('Non hai concluso l\' inserimento/modifica del corso, vuoi comunque procedere?'))
                    @this.updateAAA(type);
            }
            else
            {
                @this.updateAAA(type);
                document.body.scrollTop = document.documentElement.scrollTop = 0;
            }
        }

        function cancelAction()
        {
            if (isEditCorso)
            {
                if (confirm('Non hai concluso l\' inserimento/modifica del corso, vuoi comunque procedere?'))
                    @this.cancel();
            }
            else
                @this.cancel();
        }

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

        function store(reload) {
            window.onbeforeunload = null;
            @this.store(reload)
        }

        function updateAAA(reload) {
            window.onbeforeunload = null;
            @this.updateAAA(reload)
        }

        window.onbeforeunload = function(){
            if (isEdit)
                return 'Cambiando pagina le eventuali modifiche andranno perse';
            if (isEditCorso)
                return 'Devi prima salvare i dati del corso';

        };

        window.livewire.on('saved', () => {
            $('#userModal').modal('hide');
        });

        Livewire.on('goToAnchor', () =>
        {
            window.location.href = "#top";
        });

        $(function() {
            if (window.history && window.history.pushState) {
                window.history.pushState('', null, './');
                $(window).on('popstate', function() {

                    document.location.href = '/members';
                });
            }
        });

        function setupBackButtonHandlers() {
            const backButtons = document.querySelectorAll('a.btn--ui.lightGrey[href^="/"]');

            backButtons.forEach(button => {
                button.addEventListener('click', function(e) {
                });
            });
        }

        $(document).ready(function() {
            setupBackButtonHandlers();
        });
        document.addEventListener('livewire:load', () => {
            Livewire.on('focus-error-field', (fieldId) => {
                console.log('Validation errors received:', fieldId);
                let element;

        if (typeof fieldId === 'string') {
            element = document.getElementById(fieldId);
        } else if (Array.isArray(fieldId) && fieldId.length > 0) {
            const firstFieldId = fieldId[0];
            element = document.getElementById(firstFieldId);
            fieldId = firstFieldId; // Use the first fieldId for highlighting
        }

                if (element) {
                    element.focus();
                    element.scrollIntoView({
                        behavior: 'smooth',
                        block: 'center'
                    });

                    element.classList.add('is-invalid');

                    const label = document.querySelector(`label[for="${fieldId}"]`);
                    if (label) {
                        label.classList.add('text-danger');
                    }

                    const preserveInvalidClass = () => {
                        if (!element.classList.contains('is-invalid')) {
                            element.classList.add('is-invalid');
                        }
                    };

                    const intervalId = setInterval(preserveInvalidClass, 100);

            // Stop preserving after user interaction
            element.addEventListener('input', () => {
                clearInterval(intervalId);
            });

                } else {
                    console.warn('Element with id ' + fieldId + ' not found');
                }
            });
        });

        function downloadChart(chartId) {
            x.toBase64Image()
            var a = document.createElement('a');
            a.href = Chart.getChart(chartId).toBase64Image()
            a.download = @this.first_name + " " + @this.last_name + ' - Grafico Presenze.png';
            a.click();
            a.remove();
        }

        Livewire.on('load-chart', (mesi, valori, chartData) => {

            try {

                const ctx = document.getElementById('presenzeChart');

                try {
                    x.destroy();
                }
                catch (ee) {}

                x = new Chart(ctx, {
                        type: 'bar',
                        data: {
                            labels: mesi,
                            // datasets: [
                            //     {
                            //         label: 'Presenze',
                            //         data: valori,
                            //         borderWidth: 1
                            //     }
                            // ],
                            datasets: chartData,
                        },
                        options: {
                            responsive: true,
                            // maintainAspectRatio: false,
                            interaction: {
                                mode: 'index',
                                intersect: false,
                            },
                            scales: {
                                y: {
                                beginAtZero: true
                                }
                            },
                            plugins: {
                                legend: {
                                    display: false,
                                },
                                tooltip: {
                                    backgroundColor: 'rgba(255, 255, 255, 1)',
                                    titleColor: '#212529',
                                    bodyColor: '#495057',
                                    borderColor: '#e9ecef',
                                    borderWidth: 2,
                                    cornerRadius: 0,
                                    titleFont: {
                                        size: 18,
                                        weight: 'bold',
                                    },
                                    bodyFont: {
                                        size: 16,
                                        weight: '400',
                                    },
                                },
                            },
                        }
                    }
                );
            }
            catch(e) {
                console.log(e);
            }
        });
    </script>
@endpush
