<?php
use App\Models\FormEvento;
use App\Models\Evento;
use Carbon\Carbon;
?>
<div class="modal-header">
  <h3><i class="fas fa-pdf"></i> {{ $allegatoAnnotazione->nome }}</h3>
</div>



<div class="modal-body" >
  <div class="row justify-content-center">
    <div class="col">
      <div style="height: 70vh">
        @if($allegatoAnnotazione->path_file != null)
        <object data="{{ route('allegato_annotazione.download', ['allegato_annotazione_id' => $allegatoAnnotazione->id]) }}?type=file" width="100%" height="100%">
          Example fallback content: This browser does not support PDFs. Please download the PDF to view it.
        </object>
        @else
        <object data="{{ $allegatoAnnotazione->url_file }}" width="100%" height="100%">
          Example fallback content: This browser does not support PDFs. Please download the PDF to view it.
        </object>
        @endif
      </div>

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

  <div class="modal-footer">
    <div class="d-flex justify-content-between align-items-center w-100">
      <div class="d-flex gap-2">
        <button type="button" class="btn btn-label-secondary"
          @if($prevId) onclick="openModalAllegato({{ $prevId }})" @else disabled @endif>
          <i class="bx bx-left-arrow-alt me-1"></i>Prev
        </button>
        <button type="button" class="btn btn-label-secondary"
          @if($nextId) onclick="openModalAllegato({{ $nextId }})" @else disabled @endif>
          Next<i class="bx bx-right-arrow-alt ms-1"></i>
        </button>
      </div>
      <div class="d-flex gap-2">
        @if($allegatoAnnotazione->path_file != null)
        <a type="button" class="btn btn-primary" href="{{ route('allegato_annotazione.download', ['allegato_annotazione_id' => $allegatoAnnotazione->id]) }}?type=download">Downlad</a>
        <button type="button" class="btn btn-danger" onclick="deleteAllegatoAnnotazione()">Elimina</button>
        @endif
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Chiudi</button>
      </div>
    </div>
  </div>



<script>

$(document).ready(function(){
  $.ajaxSetup({
    headers: {
      'X-CSRF-TOKEN': '{{csrf_token()}}'
    }
  });

});


function deleteAllegatoAnnotazione(){
  Swal.fire({
    title: 'Eliminare l\'allegato?',
    text: 'Questa operazione è irreversibile.',
    icon: 'warning',
    showCancelButton: true,
    confirmButtonText: 'Elimina',
    cancelButtonText: 'Annulla',
    customClass: {
      confirmButton: 'btn btn-danger',
      cancelButton: 'btn btn-label-secondary'
    },
    buttonsStyling: false
  }).then(function (result) {
    if(result.isConfirmed){
      $.ajax({
        type: "DELETE",
        url: "{{ route('allegato_annotazione.delete') }}",
        data: {
          allegato_annotazione_id: "{{ $allegatoAnnotazione->id }}",
          _token : "{{csrf_token()}}",
        },
        success: function(){
          $("#extraLargeModal").modal('hide');
          window.location.reload();
        },
        error: function(XMLHttpRequest, textStatus, exception) { alert("Ajax failure\n" + XMLHttpRequest.responseText + "\n" + exception); },
      });
    }
  });
}


</script>
