@extends('layouts.app')

@push('styles')
    @mapstyles
@endpush

@section('content')
  @if (Auth::user()->role_id >= 5)
    <div class="container-fluid" style="height:100%">
    <div>
  @else
    <div class="container" style="margin:0 1em">
  @endif

    <div class="row">
        <div class="col-sm-7">
          <h3>Contratos Finalizados</h3>
        </div>
        <div class="col-sm-5">
          <div class="pull-right">
            {!! Form::open(['method'=>'GET','url'=>'finishedcontracts','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
    $mapMarkers = [];
    foreach ($finishedcontracts as $finishedcontract) {
      if ($finishedcontract->location) {
        $mapMarkers[] = [
            'title' => $finishedcontract->id,
            'lat' => $finishedcontract->location->getLat(),
            'lng' => $finishedcontract->location->getLng(),
            'popup' => '<h3>' . $finishedcontract->id . '</h3><p>' . $finishedcontract->address .
              '<br>' . ($finishedcontract->suppliers->company_name ?? '') . '<br>' . ucfirst($finishedcontract->categories->name ?? '') .
              '<br>' . $finishedcontract->appointment . '<br>$' . $finishedcontract->amount . '<br>' . ucfirst($finishedcontract->status->name ?? '') .
              '<br>' . $finishedcontract->score . ' de 5</p>',
        ];
      }
    }
    @endphp

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

    {{ $finishedcontracts->links() }}
</div>
@endsection
