<?php
use App\Models\Issue;
use App\Models\Config;
use Carbon\Carbon;
use Illuminate\Support\Collection;

?>

<style>
</style>

<x-app-layout>
  <x-slot name="header">
    <h2 class="font-semibold text-xl text-gray-800 leading-tight">
      <i class="fas fa-chart-bar"></i> Genera report segnalazioni
    </h2>
  </x-slot>

  <div class="row justify-content-center mb-4">
    <div class="col-xl-6 col-lg-6 col-md px-md-3 px-2">
      <div class="card">
        <div class="card-body">

          @if(Session::has('flash_message'))
          <div class="row justify-content-center mb-4">
            <div class="col">
              <div class="card alert alert-success text-center">
                {{ Session::get('flash_message') }}
              </div>
            </div>
          </div>
          @endif

          <x-auth-validation-errors class="mb-4" :errors="$errors" />

          {!! Form::open(['route' => 'issue.user_report', 'target' => '_blank']) !!}

          <div class="form-row">
            <div class="form-group col-md">
              {!! Form::label('data_inizio', 'Data inizio') !!}
              {!! Form::text('data_inizio', Carbon::now()->startOfMonth()->format('d/m/Y'), ['class' => 'form-control']) !!}
            </div>

            <div class="form-group col-md">
              {!! Form::label('data_fine', 'Data fine') !!}
              {!! Form::text('data_fine', Carbon::now()->endOfMonth()->format('d/m/Y'), ['class' => 'form-control']) !!}
            </div>
          </div>

          @if($progetti->count() == 1)
          <div class="form-row">
            <div class="form-group col-md">
              {!! Form::hidden('project_id', $progetti->get(0)->id) !!}
              <button type="submit" class="btn btn-primary"><i class="fas fa-sync-alt"></i> Genera</button>
            </div>
          </div>
          @else

          @foreach($progetti as $progetto)
          <div class="form-row">
            <div class="form-group col-md">
              <button type="submit" class="btn btn-primary" name="project_id" value="{{ $progetto->id }}" style="margin-right: 10px;"><i class="fas fa-sync-alt"></i> Genera</button> {{ $progetto->name }}
            </div>
          </div>
          @endforeach

          @endif


          {!! Form::close() !!}

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



</x-app-layout>

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

  $('#data_inizio').datetimepicker({
    locale: 'it',
    format: 'DD/MM/YYYY',
    // inline: true,
    sideBySide: true,
    icons: {
      time: "fa fa-clock-o",
      date: "fa fa-calendar",
      up: "fa fa-arrow-up",
      down: "fa fa-arrow-down",
      previous: "fa fa-chevron-left",
      next: "fa fa-chevron-right",
      today: "fa fa-clock-o",
      clear: "fa fa-trash-o"
    }
  });

  $('#data_fine').datetimepicker({
    locale: 'it',
    format: 'DD/MM/YYYY',
    // inline: true,
    sideBySide: true,
    icons: {
      time: "fa fa-clock-o",
      date: "fa fa-calendar",
      up: "fa fa-arrow-up",
      down: "fa fa-arrow-down",
      previous: "fa fa-chevron-left",
      next: "fa fa-chevron-right",
      today: "fa fa-clock-o",
      clear: "fa fa-trash-o"
    }
  });

  load_custom_fields("[name='project_id']");
});


function load_custom_fields(select){
  $('#custom_fields').load("{{ route('issue.load_custom_fields') }}?project_id="+$(select).val());
}
</script>
