@extends('app')

@section('content')
    <div class="row">
        {!! Form::open([
        'method' => 'GET',
        'action' => 'ProductController@index',
        'id' => 'searchform'
        ]) !!}
        <div class="col-md-3 searchoptions">
            <h2>{{ Lang::get('search.refine') }}:</h2>
            <hr>
            <div class="form-group">
                {!! Form::label('category', Lang::get('search.category').':') !!}
                <select name="category[]" id="category_list" class="form-control" multiple>
                    @foreach($categories as $category)
                        @if(count(Input::get('category')) != 0 and in_array($category->id, Input::get('category')))
                            <option value="{{ $category->id }}" selected>{{ $category->$lang }}</option>
                        @else
                            <option value="{{ $category->id }}">{{ $category->$lang }}</option>
                        @endif
                    @endforeach
                </select>
            </div>
            <div class="form-group categoryselect">
                {!! Form::label('fruit', Lang::get('search.fruit').':') !!}
                <select name="fruit[]" id="fruit_list" class="form-control" multiple>
                    @foreach($fruits as $fruit)
                        @if(count(Input::get('category')) == 0 or in_array($fruit->category_id, Input::get('category')))
                            @if(count(Input::get('fruit')) != 0 and in_array($fruit->id, Input::get('fruit')))
                                <option value="{{ $fruit->id }}" selected>{{ $fruit->$lang }}</option>
                            @else
                                <option value="{{ $fruit->id }}">{{ $fruit->$lang }}</option>
                            @endif
                        @else
                            <option value="{{ $fruit->id }}" disabled>{{ $fruit->$lang }}</option>
                        @endif
                    @endforeach
                </select>
            </div>
            <hr>

            <div class="form-group">
                {!! Form::label('price', Lang::get('search.price').':') !!}
                <div class="row">
                    <div class="input-group lowprice">
                        {!! Form::text('lowprice', null, ['id' => 'lowprice', 'class' => 'form-control', 'placeholder'
                        => Lang::get('search.from')]) !!}
                        <span class="input-group-addon">€/kg</span>
                    </div>
                    <span style="font-size: 21px;">&nbsp;&nbsp;- </span>

                    <div class="input-group highprice">
                        {!! Form::text('highprice', null, ['id' => 'highprice', 'class' => 'form-control', 'placeholder'
                        => Lang::get('search.to')]) !!}
                        <span class="input-group-addon">€/kg</span>
                    </div>
                </div>
            </div>

            <div class="form-group">
                {!! Form::label('amount', Lang::get('search.amount').':') !!}
                <div class="row">
                    <div class="input-group lowamount">
                        {!! Form::text('lowamount', null, ['id' => 'lowamount', 'class' => 'form-control', 'placeholder'
                        => Lang::get('search.from')]) !!}
                        <span class="input-group-addon">kg</span>
                    </div>
                    <span style="font-size: 21px;">&nbsp;&nbsp;- </span>

                    <div class="input-group highamount">
                        {!! Form::text('highamount', null, ['id' => 'highamount', 'class' => 'form-control',
                        'placeholder' => Lang::get('search.to')]) !!}
                        <span class="input-group-addon">kg</span>
                    </div>
                </div>
            </div>

            <div class="form-group">
                {!! Form::label('county', Lang::get('search.county').':') !!}
                <select name="county[]" id="county_list" class="form-control" multiple>
                    <option value="1">Harjumaa</option>
                    <option value="2">Hiiumaa</option>
                    <option value="3">Ida-Virumaa</option>
                    <option value="4">Jõgevamaa</option>
                    <option value="5">Järvamaa</option>
                    <option value="6">Läänemaa</option>
                    <option value="7">Lääne-Virumaa</option>
                    <option value="8">Põlvamaa</option>
                    <option value="9">Pärnumaa</option>
                    <option value="10">Raplamaa</option>
                    <option value="11">Saaremaa</option>
                    <option value="12">Tartumaa</option>
                    <option value="13">Valgamaa</option>
                    <option value="14">Viljandimaa</option>
                    <option value="15">Võrumaa</option>
                </select>
            </div>
        </div>
        <div class="col-md-9">

            <!-- Search Form Input -->
            <div class="input-group searchbar">
                {!! Form::text('search', Input::get('search'), [
                'class' => 'form-control',
                'placeholder' => Lang::get('search.searchplaceholder'),
                ]) !!}
                <span class="input-group-btn">
                    <button type="submit" class="btn btn-green search_button">
                        <span class="glyphicon glyphicon-search"
                              aria-hidden="true"></span> {{ Lang::get('search.button') }}
                    </button>
                </span>
            </div>

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

            <div class="btn-toolbar searchdisplayoptions">
                <div class="btn-group" data-toggle="buttons">

<!--  Checking it's selected   -->
<!-- Sales button -->
                    @if(Request::get('items') !== 'auctions')
                        <label class="btn btn-default active">
                            <input type="radio" name="items" value="sales" autocomplete="off" checked>
                    @else
                        <label class="btn btn-default">
                            <input type="radio" name="items" value="sales" autocomplete="off">
                    @endif
                        {{ Lang::get('search.sales') }}
                    </label>
        <!-- Auctions button -->
                    @if(Request::get('items') === 'auctions')
                        <label class="btn btn-default active">
                            <input type="radio" name="items" value="sales" autocomplete="off" checked>
                    @else
                        <label class="btn btn-default">
                            <input type="radio" name="items" value="sales" autocomplete="off">
                    @endif
                        {{ Lang::get('search.auctions') }}
                        </label>
                </div>
                <div class="btn-group result-display" style="float:right; left:-50%; position:relative;">
                    <span style="float:left; font-size: 21px;">&nbsp; {{ Lang::get('search.view') }} &nbsp;</span>
                    <button type="button" class="btn btn-default selected">
                        <span class="glyphicon glyphicon-th" aria-hidden="true"></span>
                    </button>

                    <button type="button" class="btn btn-default">
                        <span class="glyphicon glyphicon-th-list" aria-hidden="true"></span>
                    </button>
                </div>

                <div class="btn-group" style="float:right; position:relative;" role="group">
                    <span style="float:left; font-size:21px;">&nbsp; {{ Lang::get('search.sort') }}&nbsp;</span>
                    <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"
                            aria-expanded="false">
                        {{ Lang::get('search.date') }} <span class="glyphicon glyphicon-arrow-up"></span>
                        <span class="caret"></span>
                    </button>
                    <ul class="dropdown-menu" role="menu">
                        <li><a href="#">{{ Lang::get('search.date') }} <span
                                        class="glyphicon glyphicon-arrow-down"></span></a></li>
                        <li><a href="#">{{ Lang::get('search.price') }} <span
                                        class="glyphicon glyphicon-arrow-up"></span></a></li>
                        <li><a href="#">{{ Lang::get('search.price') }} <span
                                        class="glyphicon glyphicon-arrow-down"></span></a></li>
                        <li><a href="#">{{ Lang::get('search.amount') }} <span
                                        class="glyphicon glyphicon-arrow-up"></span></a></li>
                        <li><a href="#">{{ Lang::get('search.amount') }} <span
                                        class="glyphicon glyphicon-arrow-down"></span></a></li>
                    </ul>
                </div>


            </div>
            <hr>
            <!--  <nav class="pagin">
                  <ul class="pagination">
                      <li>
                          <a href="#" aria-label="Previous">
                              <span aria-hidden="true">&laquo;</span>
                          </a>
                      </li>
                      <li><a href="#">1</a></li>
                      <li><a href="#">2</a></li>
                      <li><a href="#">3</a></li>
                      <li><a href="#">4</a></li>
                      <li><a href="#">5</a></li>
                      <li>
                          <a href="#" aria-label="Next">
                              <span aria-hidden="true">&raquo;</span>
                          </a>
                      </li>
                  </ul>
              </nav>
  -->
            <div class="flex-container">
                @if(Request::get('items') === 'auctions')
                    @include('partials.auctionlist');
                @else
                    @include('partials.productlist');
                @endif

            </div>

            <!--
              <nav class="pagin">
                  <ul class="pagination">
                      <li>
                          <a href="#" aria-label="Previous">
                              <span aria-hidden="true">&laquo;</span>
                          </a>
                      </li>
                      <li><a href="#">1</a></li>
                      <li><a href="#">2</a></li>
                      <li><a href="#">3</a></li>
                      <li><a href="#">4</a></li>
                      <li><a href="#">5</a></li>
                      <li>
                          <a href="#" aria-label="Next">
                              <span aria-hidden="true">&raquo;</span>
                          </a>
                      </li>
                  </ul>
              </nav> -->
        </div>
    </div>

@endsection

@section('footer')

    <script>
        $('#category_list').select2({});
        $('#county_list').select2({});
        $('#fruit_list').select2({});

        $('input:radio[name=items]').change(function(){
            $('#searchform').submit();
        });
    </script>
@endsection