@extends('layouts.master')


@section('title', 'Products')


@section('nav')
    @include('layouts.nav')
@endsection


@section('content')

        <form action="{{ route('products.filter') }}" method="get">
            <div class="row">
                <div class="form-group col-lg-3">
                    <select name="countries" class="form-control">
                        <option value="" selected>Any Country</option>
                        @foreach($countries as $item)
                             <option value="{{ $item->id }}">{{ $item->name }}</option>
                        @endforeach
                    </select>
                </div>

                <div class="form-group col-lg-3">
                    <select name="carriers" class="form-control">
                        <option value="" selected>Any Carrier</option>
                        @foreach($carriers as $item)
                            <option value="{{ $item->id }}">{{ $item->name }}</option>
                        @endforeach
                    </select>
                </div>

                <div class="col-lg-3">
                    <button class="btn btn-primary">Search</button>
                </div>

            </div>
        </form>


        <table class="table">
            <thead>
                <tr>
                    <th>Id</th>
                    <th>Is Active</th>
                    <th>SKU</th>
                    <th>Carrier</th>
                    <th>Contry</th>
                    <th>Full Amount</th>
                    <th>User Discount %</th>
                    <th>Telecom Discount %</th>
                    <!--<th>Presented Amount (Savings)</th>-->
                    <th>Is Pinless?</th>
                </tr>
            </thead>

            <tbody>
                @foreach($products as $item)
                    <tr>
                        <td>{{ $item->id }}</td>

                        @if($item->active == true)
                            <td>
                                <form action="{{ route('products.update', [$item->id]) }}" method="post">
                                    <input type="hidden" name="_method" value="put" />
                                    <input type="hidden" name="active" value="0">
                                    <button type="submit">
                                        <span class="glyphicon glyphicon-ok-sign"></span>
                                    </button>
                                    {{ csrf_field() }}
                                </form>
                            </td>
                        @else
                            <td>
                                <form action="{{ route('products.update', [$item->id]) }}" method="post">
                                    <input type="hidden" name="_method" value="put" />
                                    <input type="hidden" name="active" value="1">
                                    <button type="submit">
                                        <span class="glyphicon glyphicon-remove-sign"></span>
                                    </button>
                                    {{ csrf_field() }}
                                </form>
                            </td>
                        @endif
                        <td>{{ $item->sku }}</td>                  
                        <td>{{ $item->carrier }}</td>                  
                        <td>{{ $item->country }}</td>                  
                        <td>${{ number_format( (double)preg_replace('/[^$0-9.]/', '', $item->amount ), 2) }}</td>

                        
                        <td> 
                            <form action="{{ route('products.update', [$item->id]) }}" method="post" class="formupdate">
                                <input type="hidden" name="_method" value="put" />
                                <input style="width: 50px" class="discount_pct" type="number" name="discount_pct" value="{{ $item->discount_pct }}">
                                {{ csrf_field() }}
                                <button type="submit">
                                    <span class="glyphicon glyphicon-refresh"></span>
                                </button>
                            </form>
                        </td>
                        
                        
                        <td> 
                            <form action="{{ route('products.update', [$item->id]) }}" method="post" class="formupdate">
                                <input type="hidden" name="_method" value="put" />
                                <input style="width: 50px" class="telecom_pct" type="number" name="telecom_pct" value="{{ $item->telecom_pct }}">
                                {{ csrf_field() }}
                                <button type="submit">
                                    <span class="glyphicon glyphicon-refresh"></span>
                                </button>
                            </form>
                        </td>
                        
                        
                        @if($item->is_pinless == 0)
                            <td>false</td>
                        @else
                            <td>true</td>
                        @endif
                    </tr>
                @endforeach
            </tbody>

        </table>




        {{ $products->appends(request()->input())->links() }}



@endsection


@section('js')
    
    <script type="text/javascript">


        /*$(document).ready(function(){
            
            var url = window.location.origin + '/';
            

            $.ajax({
                url: url + 'allproducts',

                success: function(result){
                    console.log(result);
                }
            });

            


        });*/


    </script>

@endsection