@extends('layouts.app')

@section('content')
  <script src="{{ asset('js/ajaxcrud.js') }}"></script>
  @if (Auth::user()->role_id >= 5)
    <div class="container-fluid" style="height:100%">
    @include('sidebar')
    <div style="width:90%; float: left; margin:1em 0 0 1em">
  @else
    <div class="container" style="margin:0 1em">
  @endif

    <div class="row">
        <div class="col-sm-7">
          <h3>Comentarios del reporte</h3>
        </div>
    </div>

    <br>
    <h5>Contrato:</h5>
    <table class="table">
        <thead>
        <tr>
          <th style="vertical-align: middle">ID</th>

          <th style="vertical-align: middle">Usuario</th>

          <th style="vertical-align: middle">Proveedor</th>

          <th style="vertical-align: middle">Categoría</th>

          <th style="vertical-align: middle">Dirección</th>

          <th style="vertical-align: middle">Cita</th>

          <th style="vertical-align: middle">Monto</th>

          <th style="vertical-align: middle">Calificación</th>

          <th style="vertical-align: middle">Comentarios</th>

          <th style="vertical-align: middle">Transacción ID</th>

          <th style="vertical-align: middle">Fecha de creación</th>

          <th style="vertical-align: middle">Fecha de fuera de casa</th>

          <th style="vertical-align: middle">Confirmación de descripción de la casa</th>

        </tr>
        </thead>
        <tbody>
        @php
            $i=1;
        @endphp
          <tr>
            <th>{{ $contract->id }}</th>
            <td>{{ $contract->user->name ?? null }}</td>
            <td>{{ $contract->suppliers->company_name ?? null }}</td>
            <td>{{ $contract->categories->name ?? null }}</td>
            <td>{{ $contract->address }}</td>
            <td>{{ $contract->appointment }}</td>
            <td>${{ $contract->amount }}</td>
            <td>{{ $contract->score }}</td>
            <td>{{ $contract->comments }}</td>
            <td>{{ $contract->transaction_id }}</td>
            <td>{{ $contract->created_at }}</td>
            <td>{{ isset($nohome->confirmed_at) }}</td>
            <td>{{ isset($nohome->house_description) }}</td>
        </tr>
        </tbody>
    </table>
    <br><br>
    <h5>Comentarios:</h5>
    <table class="table">
        <thead>
        <tr>
            <th style="vertical-align: middle"><a href="{{url('comments?field=user_id&sort='.(request()->session()->get('sort')=='asc'?'desc':'asc'))}}">Usuario</a></th>
                {{request()->session()->get('field')=='user_id'?(request()->session()->get('sort')=='asc'?'':''):''}}

            <th style="vertical-align: middle"><a href="{{url('comments?field=user_id&sort='.(request()->session()->get('sort')=='asc'?'desc':'asc'))}}">Teléfono</a></th>
                {{request()->session()->get('field')=='user_id'?(request()->session()->get('sort')=='asc'?'':''):''}}

            <th style="vertical-align: middle"><a href="{{url('comments?field=comment&sort='.(request()->session()->get('sort')=='asc'?'desc':'asc'))}}">Comentario</a></th>
                {{request()->session()->get('field')=='comment'?(request()->session()->get('sort')=='asc'?'':''):''}}

            <th style="vertical-align: middle"><a href="{{url('contracts?field=created_at&sort='.(request()->session()->get('sort')=='asc'?'desc':'asc'))}}">Fecha de creación</a></th>
                {{request()->session()->get('field')=='created_at'?(request()->session()->get('sort')=='asc'?'':''):''}}

        </tr>
        </thead>
        <tbody>
        @php
            $i=1;
        @endphp
        @foreach ($comments as $comment)
          <tr>
            <td>{{ $comment->user->name }}</td>
            <td>{{ $comment->user->phone }}</td>
            <td>{{ $comment->comment }}</td>
            <td>{{ $comment->created_at }}</td>
            <td style="width: 3em">
              <input type="hidden" name="_method" value="delete"/>
                <a class="btn btn-danger btn-xs" title="Delete"
                   href="javascript:if(confirm('¿Estás seguro de que quieres eliminar este comentario?')) javascript:if(confirm('Usualmente no se deben eliminar comentarios, solo editarlos ¿Estás seguro?')) ajaxDeleteComments('{{url('reports/comments/delete/'.$comment->id.'/'.$contract->id)}}','{{csrf_token()}}')">
                   <i class="fa fa-trash"></i>
                </a>
            </td>
        </tr>
        @endforeach

        </tbody>
    </table>

        <ul class="pagination">
            {{ $comments->links() }}
        </ul>
</div>
@endsection
