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

    <header id="title--section" style="display:none !important"  class="d-flex align-items-center justify-content-between">
        <div class="title--section_name d-flex align-items-center justify-content-between">
            <i class="ico--ui title_section utenti me-2"></i>
            <h2 class="primary">@if(!$add && !$update)Tessere @else Inserimento/modifica tessera @endif</h2>
        </div>

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

    </header>


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

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

        <!--<button id="open-filter" onclick="pcsh1()"></button>
        <button id="close-filter" onclick="pcsh2()"></button>-->

        <!--
        <section id="subheader" class="d-flex align-items-center justify-content-between">
            <form action="" class="group--action d-flex align-items-center">
            <select class="form-select form-select-lg me-1" aria-label=".form-select-lg example">
                <option selected>Open this select menu</option>
                <option value="1">One</option>
                <option value="2">Two</option>
                <option value="3">Three</option>
                </select>
                <button type="submit" class="btn--ui">applica</button>
            </form>

            <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">
                    <button class="btn--ui" type="button" id="button-addon2"><i class="ico--ui search"></i>Cerca</button>
                </div>
            </form>
        </section>
        -->
        <section id="resume-table">
            <div class="compare--chart_wrapper d-none"></div>

            <table class="table tablesaw tableHead tablesaw-stack" id="tablesaw-350" width="100%">
                <thead>
                    <tr>
                        <th scope="col" >Nome</th>
                        <th scope="col" >Giorno scadenza</th>
                        <th scope="col" >Mese scadenza</th>
                        <th scope="col" >Abilitato</th>
                        <th scope="col">...</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach($records as $record)
                        <tr>
                            <td>{{$record->name}}</td>
                            <td>{{$record->next_day_expire}}</td>
                            <td>{{$record->next_month_expire}}</td>
                            <td> <span class="tablesaw-cell-content"><span class="badge tessera-badge {{$record->enabled ? 'active' : 'suspended'}}">{{$record->enabled ? 'attivo' : 'disattivo'}}</span></span></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

                </tbody>
            </table>
            <!--
            <div class="paginator d-flex justify-content-center">
                <nav aria-label="Page navigation example">
                    <ul class="pagination">
                        <li class="page-item">
                        <a class="page-link" href="#" aria-label="Previous">
                            <span aria-hidden="true"></span>
                        </a>
                        </li>
                        <li class="page-item"><a class="page-link" href="#">1</a></li>
                        <li class="page-item"><a class="page-link" href="#">2</a></li>
                        <li class="page-item"><a class="page-link" href="#">3</a></li>
                        <li class="page-item"><a class="page-link" href="#">3</a></li>

                        <li class="page-item"><span class="more-page">...</span></li>

                        <li class="page-item">
                        <a class="page-link" href="#" aria-label="Next">
                            <span aria-hidden="true"></span>
                        </a>
                        </li>
                    </ul>
                    </nav>
            </div>
            -->
        </section>

    @else

        <div class="container">

            <a class="btn--ui lightGrey" href="/cards"><i class="fa-solid fa-arrow-left"></i></a><br><br>

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

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

                    <form action="">

                        <div class="row mb-3">
                            <div class="col">
                                <div class="form--item">
                                    <label for="inputName" class="form-label">Nome</label>
                                    <input class="form-control js-keyupTitle @error('name') is-invalid @enderror" type="text" id="name" placeholder="Nome" wire:model="name">
                                    @error('name')
                                        <div class="invalid-feedback">{{ $message }}</div>
                                    @enderror
                                </div>
                            </div>
                        </div>

                        @if(!$one_year_expire)
                            <div class="row mb-3">
                                <div class="col">
                                    <div class="form--item">
                                        <label for="next_day_expire" class="form-label">Giorno scadenza</label>
                                        <input class="form-control" type="text" id="next_day_expire" placeholder="Giorno" wire:model="next_day_expire">
                                    </div>
                                </div>
                                <div class="col">
                                    <label for="next_month_expire" class="form-label">Mese scadenza</label>
                                    <select name="next_month_expire" class="form-select" aria-label="Seleziona una nazione" wire:model="next_month_expire">
                                        <option value="">--Seleziona--
                                        <option value="1">Gennaio
                                        <option value="2">Febbraio
                                        <option value="3">Marzo
                                        <option value="4">Aprile
                                        <option value="5">Maggio
                                        <option value="6">Giugno
                                        <option value="7">Luglio
                                        <option value="8">Agosto
                                        <option value="9">Settembre
                                        <option value="10">Ottobre
                                        <option value="11">Novembre
                                        <option value="12">Dicembre
                                    </select>
                                </div>

                            </div>
                        @endif

                        <div class="form--item mb-3">
                            <div class="form-check form-check-inline">
                                <input class="form-check-input" type="radio" id="one_year_expire" value="0" wire:model="one_year_expire">
                                <label class="form-check-label" for="one_year_expire">&nbsp;Scadenza a data  fissa</label>
                            </div>
                        </div>
                        <div class="form--item mb-3">
                            <div class="form-check form-check-inline">
                                <input class="form-check-input" type="radio" id="one_year_expire" value="1" wire:model="one_year_expire">
                                <label class="form-check-label" for="one_year_expire">&nbsp;Scadenza ad un anno</label>
                            </div>
                        </div>

                        <div class="form--item mb-3">
                            <div class="form-check form-check-inline" style="padding-left:0px !important;">
                                <input class="form-check-input form-control" style="width:22px; height:22px;" type="checkbox" id="enabled" wire:model="enabled">
                                <label class="form-check-label" for="enabled">Abilitato</label>
                            </div>
                        </div>

                        <div class="form--item mb-3">
                            <div class="form-check form-check-inline" style="padding-left:0px !important;">
                                <input class="form-check-input form-control" style="width:22px; height:22px;" type="checkbox" id="enabled" wire:model="use_for_user_check">
                                <label class="form-check-label" for="use_for_user_check">Utilizza per utente tesserato</label>
                            </div>
                        </div>



                        <!-- // inline input field -->

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

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

    @endif
</div>

@push('scripts')
    <link href="/css/datatables.css" rel="stylesheet" />
    <script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
    <script src="/assets/js/datatables.js"></script>
    <script src="https://cdn.datatables.net/buttons/3.0.2/js/buttons.dataTables.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/pdfmake.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/vfs_fonts.js"></script>
@endpush

@push('scripts')
    <script>

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

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

        function loadDataTable(){
            if ( $.fn.DataTable.isDataTable('#tablesaw-350') ) {
                $('#tablesaw-350').DataTable().destroy();
            }
            $('#tablesaw-350').DataTable({
                layout: {
                    topStart : null,
                    topEnd : null,
                    top1A: {
                        buttons: [
                            {
                                extend: 'collection',
                                text: 'ESPORTA',
                                buttons: [
                                    {
                                    extend: 'excelHtml5',
                                        title: 'Tessere',
                                        exportOptions: {
                                            columns: ":not(':last')"
                                        }
                                    },
                                    {
                                        extend: 'pdfHtml5',
                                        title: 'Tessere',
                                        exportOptions: {
                                            columns: ":not(':last')"
                                        }
                                    },
                                    {
                                        extend: 'print',
                                        text: 'Stampa',
                                        title: 'Tessere',
                                        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
                        }
                    }
                },

                //},
                //dom: '<"row"<"col-4"B><"col-4"l><"col-4"f>>rtip',
                //dom: '<"top"><"row top"<"col-6"B><"col-6"f>>rt<"bottom"<"row"<"col-4"p><"col-4"l><"col-4 rightPagination"i>>><"clear">',
                //"dom": '<"top"i>rt<"bottom"flp><"clear">',
                lengthChange: true,
                pagingType: 'first_last_numbers',
                language: {
                    "url": "/assets/js/Italian.json",
                    paginate: {
                        first: '<i class="fa-solid fa-angles-left"></i>',
                        last: '<i class="fa-solid fa-angles-right"></i>',
                    }
                },
                "fnInitComplete": function (oSettings, json) {
                    var html = '&nbsp;<a href="#" class="addData btn--ui"><i class="fa-solid fa-plus"></i></a>';
                    $(".dt-search").append(html);
                }
            });
            $('#tablesaw-350 thead tr th').addClass('col');
            $('#tablesaw-350 thead tr th').css("background-color", "#f6f8fa");
             $(document).ready(function() {
                $(document).on("click",".addData",function() {
                    $(".title--section_addButton").trigger("click")
                });
            } );
        }

    </script>
@endpush
