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

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

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