@extends('backend._partials.app')
@section('maincontent')
    <style>
        .sweet-content p{
            text-align: justify!important;
        }
    </style>
    <div class="col-md-12">
        <div class="card">
            <div class="header">
                <button data-toggle="modal" data-target="#modal" onclick="loadModal('exchange-apply')"
                        class="btn btn-info btn-fill pull-right">EXCHANGE REQUEST <i class="fa fa-plus" aria-hidden="true"></i></button>
                <h4 class="title">Exchange Statistics</h4>
            </div>
            <div class="content">
                <div class="row">
                    <div class="col-md-6 col-md-offset-3">
                        {!! Form::open(['url'=>'exchange']) !!}
                        {!! Form::hidden('search','yes') !!}
                        <div class="col-md-5">
                            <label>FROM</label>
                            <div class="form-group">
                                <input type="text" name="from_date" class="form-control datepicker"
                                       placeholder="From Date here"/>
                            </div>
                        </div>
                        <div class="col-md-5">
                            <label>TO</label>
                            <div class="form-group">
                                <input type="text" name="to_date" class="form-control datepicker"
                                       placeholder="To Date Here"/>
                            </div>
                        </div>
                        <div class="col-md-2">
                            <label>&nbsp;</label>
                            <div class="form-group">
                                <button class="btn btn-info btn-fill" type="submit">Search</button>
                            </div>
                        </div>
                        {!! Form::close() !!}
                    </div>
                    <div class="col-md-12">
                        <div class="fresh-datatables">
                            <table id="datatable" class="table table-striped table-bordered table-hover" cellspacing="0"
                                   width="100%" style="width:100%">
                                <thead>
                                <tr>
                                    <th>Sl</th>
                                    <th>Message</th>
                                    <th>Reply</th>
                                    <th>Exchange From</th>
                                    <th>Exchange To</th>
                                    <th>Apply date</th>
                                    <th>Reviewed At</th>
                                    <th>Status</th>
                                    <th>Action</th>
                                </tr>
                                </thead>
                                <tbody>
                                <?php $i = 0; ?>
                                @forelse($results as $result)
                                    @if($result->viewed==0 && $result->status!=0)
                                        <tr onclick="updateNotifyView('{{$result->id}}',this)" style="background-color:#C8FFC8; cursor:pointer">
                                    @else
                                        <tr>
                                            @endif
                                            <td>{{++$i}}</td>
                                            <td>

                                                @if(strlen($result->message)>30)
                                                    {{strip_tags(substr($result->message,0,30))}}....<a href="javascript:void(0)" onclick="getDetails({{$result}})">more</a>
                                                @else
                                                    {{strip_tags($result->message)}}
                                                @endif
                                            </td>
                                            <td>

                                                @if(strlen($result->reply)>20)
                                                    {{substr($result->reply,0,20)}}....<a href="javascript:void(0)" onclick="getDetails({{$result}})">more</a>
                                                @else
                                                    {{$result->reply}}
                                                @endif
                                            </td>
                                            <td>{{$result->holiday_date}}</td>
                                            <td>{{$result->desire_date}}</td>
                                            <td>{{$result->created_at}}</td>
                                            <td>{{$result->action_at}}</td>
                                            <td>
                                                @if($result->status=='1')
                                                    <label class="label label-success">Approved</label>
                                                @elseif($result->status=='0')
                                                    <label class="label label-danger">Pending</label>
                                                @else
                                                    <label class="label label-warning">Denied</label>
                                                @endif
                                            </td>
                                            <td>
                                                <a href="#" class="btn btn-simple btn-warning btn-icon" @if($result->status==0)
                                                data-toggle="modal" data-target="#modal"
                                                   onclick="loadModalEdit('exchange-edit',{{$result->id}},'edit')" @else disabled title="You can't edit exchange"  @endif><i class="fa fa-edit"></i></a>
                                                <a @if($result->status==1) disabled title="You can't delete approved exchange" @else onclick="deleteConfirm('exchange-delete',{{$result->id}})"  @endif href="javascript:void(0)"
                                                   class="btn btn-simple btn-danger btn-icon remove"><i
                                                            class="fa fa-times"></i></a>
                                            </td>
                                        </tr>
                                        @empty
                                            <tr>
                                                <td colspan="9">No request yet</td>
                                            </tr>
                                        @endforelse
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script type="text/javascript">
        function updateNotifyView(exchangeId,obj) {
            $.ajax({
                url: "{{URL::to('/')}}/exchange-notification-view/"+exchangeId ,
                type: 'GET', // define the type of HTTP verb we want to use (POST for our form)
                dataType: 'json',
                success: function (data) {
                    if(data.status=='success'){
                        $(obj).css({'background-color':'transparent'});
                    }
                }
            });
        }
        function getDetails(exchange) {
            var reply= (exchange.reply==null)?'No reply':exchange.reply;
            swal({  title: 'Exchange Application',
                confirmButtonText: 'Close',
                confirmButtonClass: "btn btn-danger",
                html:'<b>Message:</b><p style="text-align: justify; float:left;">'+exchange.message+'</p>'+
                '<b>Reply:</b><p style="text-align: justify;">'+reply+'</p>'
            });
        }

    </script>
    <script src="{{asset('public/vendor/unisharp/laravel-ckeditor/ckeditor.js')}}"></script>
@endsection