<div class="m-3">

    <div class="row mb-3">
        <div class="col-6">
            <h2>{{$title}}</h2>
        </div>
        <div class="col-md-6 text-right">
            @if(!$add && !$update)
                <button wire:click="add()" type="button" class="btn btn-block btn-success float-right"
                    style="max-width:150px">Aggiungi</button><br>
            @endif
        </div>
    </div>

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

        <div>

            <div class="card">

                <div class="card-header">

                    <div class="card-tools">
                        <div class="input-group input-group-sm" style="width: 300px;">
                            <input type="text" name="search" wire:model="search" class="form-control float-right"
                                placeholder="Cerca">

                            <div class="input-group-append">
                                <button type="submit" class="btn btn-default">
                                    <i class="fas fa-search"></i>
                                </button>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="card-body table-responsive p-0">
                    <table class="table table-hover text-nowrap">
                        <thead>
                            <tr>
                                <th>Codice toponimo</th>
                                <th>Toponimo</th>
                                <th>Nome</th>
                                <th style="width:150px">&nbsp;</th>
                                <th style="width:150px">&nbsp;</th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach($records as $record)
                                <tr>
                                    <td>{{$record->CODICETOPONIMO}}</td>
                                    <td>{{$record->TOPONIMO}}</td>
                                    <td>{{$record->DESCRIZIONE}}</td>
                                    <td><button wire:click="edit({{ $record->id }})" type="button"
                                            class="btn btn-primary btn-block"><i class="fa fa-edit"></i>&nbsp;Modifica</button>
                                    </td>
                                    <td><button onclick="confirm('Sei sicuro?') || event.stopImmediatePropagation()"
                                            wire:click="delete({{ $record->id }})" type="button"
                                            class="btn btn-danger btn-block"><i class="fa fa-trash"></i>&nbsp;Elimina</button>
                                    </td>
                                </tr>
                            @endforeach
                        </tbody>

                    </table>

                </div>

                <div class="card-footer clearfix">

                    <ul class="pagination pagination-sm m-0 float-right">

                        {{ $records->links() }}

                    </ul>

                </div>


            </div>
        </div>

    @else

        <div class="card card-primary">

            <form>

                <div class="card-header">
                    <h3 class="card-title"><b>Inserimento/Modifica</b></h3>
                </div>

                <div class="card-body">
                    <div class="form-group">
                        <label for="toponimo">Toponimo</label>
                        <input class="form-control" type="text" id="toponimo" placeholder="Toponimo" wire:model="toponimo">
                    </div>
                    <div class="form-group">
                        <label for="descrizione">Nome</label>
                        <input class="form-control @error('descrizione') is-invalid @enderror" type="text" id="name"
                            placeholder="Nome" wire:model="descrizione">
                        @error('descrizione')
                            <div class="invalid-feedback">{{ $message }}</div>
                        @enderror
                    </div>
                    <div class="form-group">
                        <label for="codicetoponimo">codice Toponimo</label>
                        <input class="form-control" type="text" id="codicetoponimo" placeholder="Codice Toponimo"
                            wire:model="codicetoponimo">
                    </div>
                </div>

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

    @endif

</div>
