@extends('layouts.app')

@section('content')
  @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>Contratos actuales</h3>
        </div>
        <div class="col-sm-5">
          <div class="pull-right">
            {!! Form::open(['method'=>'GET','url'=>'currentcontracts','class'=>'navbar-form navbar-left','role'=>'search'])  !!}
            <div class="input-group">
                <input class="form-control" id="search"
                       value="{{ request()->session()->get('search') }}"
                       placeholder="Buscar" name="search"
                       type="text" id="search"/>
                <div class="input-group-btn">
                    <button type="submit" class="btn btn-primary">
                            <i class="fa fa-search" aria-hidden="true"></i>
                    </button>
                </div>
            </div>
            {!! Form::close() !!}
          </div>
        </div>
    </div>

    @php
    $markers=array();

    foreach ($currentcontracts as $currentcontract) {
      $markers[] =
      [
          'title' => $currentcontract->id,
          'lat' =>  $currentcontract->location->getLat(),
          'lng' => $currentcontract->location->getLng(),
          'popup' => '<h3>' . $currentcontract->id . '</h3><p>' . $currentcontract->address .
            '<br>' . $currentcontract->suppliers->company_name ?? null . '<br>' . ucfirst($currentcontract->categories->name ?? null) .
            '<br>' . $currentcontract->appointment . '<br>$' . $currentcontract->amount . '<br>' . ucfirst($currentcontract->status->name) .
            '<br>' . $currentcontract->score . ' de 5</p>',
      ];
    }
    $markers_json = str_replace(":", " => " ,str_replace("}", "]", str_replace("{", "[", json_encode($markers))));
    @endphp

    @map([
      'lat' => 20.659698,
      'lng' => -103.349609,
      'zoom' => 12,
      $markers_json
    ])

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