@extends('backend._partials.app')
@section('maincontent')
    <div class="col-md-12">
        <div class="card">
            <div class="header">
                Details Report :: Exchange
                <p class="category">Including approved &amp; pending </p>
            </div>
            <div class="content">
                <div class="row">
                    <div class="col-md-6 col-md-offset-3">
                        {!! Form::open(['url'=>'exchange-reports']) !!}
                        {!! 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 fromdatepicker"
                                       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 todatepicker"
                                       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="header text-center">
                            <h5 class="title"><strong>{{$from_date}}</strong> to <strong>{{$to_date }}</strong></h5>
                        </div>
                        <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>Image</th>
                                    <th>Name</th>
                                    <th>Message</th>
                                    <th>Exchange From</th>
                                    <th>Exchange To</th>
                                    <th>Apply date</th>
                                    <th>Reviewed at</th>
                                    <th>Status</th>
                                </tr>
                                </thead>
                                <tbody>
                                <?php $i=0; ?>
                                @forelse($exchanges as $exchange)
                                    <tr onclick="getDetails({{$exchange}})" style="cursor: pointer;">
                                        <td>{{++$i}}</td>
                                        <td>@if(empty($exchange->user->image))
                                                <img src="{{asset("public/img/users/default-avatar.png")}}" height="40">
                                            @else
                                                <img src="{{asset("public/img/users")."/".$exchange->user->image}}" height="40">

                                            @endif</td>
                                        <td>{{$exchange->user->first_name." ".$exchange->user->last_name}}</td>
                                        <td>

                                            @if(strlen($exchange->message)>2)
                                                {{ strip_tags(substr($exchange->message,0,25))}}....
                                            @else
                                                {{ strip_tags($exchange->message)}}
                                            @endif
                                        </td>
                                        <td>{{$exchange->holiday_date}}</td>
                                        <td>{{$exchange->desire_date}}</td>

                                        <td>{{$exchange->created_at}}</td>
                                        <td>{{$exchange->action_at}}</td>
                                        <td>
                                            @if($exchange->status=='1')
                                                <label class="label label-success">Approved</label>
                                            @elseif($exchange->status=='0')
                                                <label class="label label-danger">Pending</label>
                                            @else
                                                <label class="label label-warning">Denied</label>
                                            @endif
                                        </td>

                                    </tr>
                                @empty
                                    <tr>
                                        <td colspan="10" align="center">No record found!</td>
                                    </tr>
                                @endforelse
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        function getDetails(data) {
            var reply= (data.reply==null)?'No reply':data.reply;
            swal({  title: 'Exchange Application',
                confirmButtonText: 'Close',
                confirmButtonClass: "btn btn-danger",
                html:'<b>Message:</b><p style="text-align: justify;float:left;">'+data.message+'</p>'+
                '<b>Reply:</b><p style="text-align: justify;">'+reply+'</p>'
            });
        }
    </script>
@endsection