<div class="card card-primary">
    <div class="card-header">
        <h3 class="card-title">Gestione richieste</h3>
    </div>
    <div class="card-body">
        <div class="row">
            <table class="table table-hover text-nowrap">
                <thead>
                    <tr>
                        <th>Richiedente</th>
                        <th>Data richiesta</th>
                        <th>Data consegna</th>
                        <th>Nota</th>
                        <th style="width:100px">&nbsp;</th>
                        <th style="width:100px">&nbsp;</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach ($richieste as $richiesta)
                        <tr>
                            <td>{{ $this->getAnagrafica($richiesta->anagrafica_id) }}
                            </td>
                            <td>{{ $richiesta->data_richiesta ? date('d/m/Y', strtotime($richiesta->data_richiesta)) : '' }}
                            </td>
                            <td>{{ $richiesta->consegna_richiesta ? date('d/m/Y', strtotime($richiesta->consegna_richiesta)) : '' }}
                            </td>
                            <td style="white-space: normal;max-width: 150px;">
                                {{ $richiesta->description }}
                            </td>
                            <td><button wire:click="editRichiesta({{ $richiesta->id }})" type="button"
                                    class="btn btn-primary btn-block"
                                    style="background-color: orange;border-color: orange;"><i
                                        class="fa fa-edit"></i></i></button>
                            </td>
                            <td><button onclick="confirm('Sei sicuro?') || event.stopImmediatePropagation()"
                                    wire:click.prevent="removeRichiesta({{ $richiesta->id }})" type="button"
                                    class="btn btn-success btn-block"><i class="fa fa-trash"></i>&nbsp;</button>
                            </td>
                        </tr>
                    @endforeach
                </tbody>
            </table>
        </div>
        <div class="row">
            <div class="col-sm-4">
                <div class="form-group">
                    <label>Richiedente</label>
                    <select
                        class="form-control richiestaAnagrafica @error('richiestaAnagrafica') is-invalid @enderror"
                        style="width:100%">
                        <option value="{{ $richiestaAnagrafica }}">
                            {{ $this->getAnagrafica($richiestaAnagrafica) }}
                    </select>
                </div>
            </div>
            <div class="col-sm-4">
                <div class="form-group">
                    <label>Data richiesta</label>
                    <input class="form-control @error('richiestaData') is-invalid @enderror" type="date"
                        wire:model="richiestaData">
                </div>
            </div>
            <div class="col-sm-4">
                <div class="form-group">
                    <label>Data consegna</label>
                    <input class="form-control @error('richiestaConsegna') is-invalid @enderror" type="date"
                        wire:model="richiestaConsegna">
                </div>
            </div>
        </div>
        <div class="row">
            <textarea class="form-control" rows="5" wire:model="richiestaText"></textarea>
            @if (!$this->validated)
                <button type="button" class="btn btn-primary mt-2"
                    wire:click.prevent="saveRichiesta()">Aggiungi</button>
            @else
                    <button type="button" class="btn btn-primary mt-2"
                        wire:click.prevent="saveRichiesta()">Aggiungi e Salva</button>
                @endif
        </div>
    </div>
</div>
