@section('title', 'Complaints Management')
@section('complaints-management', 'active')
@include('adminDashboard.layout.header')

<div class="main-content">
    <section class="section">
        <div class="section-body">
            <div class="row">
                <div class="col-12">
                    <div class="card">
                        <div class="card-header">
                            <h4>Complaints</h4>
                        </div>
                        <div class="card-body p-0">
                            <div class="table-responsive">
                                <table class="table table-striped table-md">
                                    <tr>
                                        <th>ID</th>
                                        <th>Mobile</th>
                                        <th>Whatsapp</th>
                                        <th>Description</th>
                                        <th>Reply</th>
                                        <th>Status</th>
                                        <th>Action</th>
                                    </tr>
                                    @foreach($complaints as $key => $complaint)
                                    <tr>
                                        <td>{{$key}}</td>
                                        <td>
                                            @if (env('DEMO'))
                                            {{ substr_replace($complaint->mobile, '*****', 3, 5) }}
                                            @else
                                            {{$complaint->mobile}}
                                            @endif
                                        </td>
                                        <td>{{$complaint->whatsapp}}</td>
                                        <td>{{$complaint->description}}</td>
                                        <td>{{$complaint->reply}}</td>
                                        <td>
                                            @if($complaint->status == 0)
                                            Waiting
                                            @elseif($complaint->status == 1)
                                            Replied
                                            @endif
                                        </td>
                                        <td>
                                            @if($complaint->status == 0)
                                            <button type="button" onclick="replyToComplaint('{{$complaint->id}}')" class="badge badge-success" style="border:none;" data-toggle="modal" data-target="#exampleModal"><i class="fas fa-ellipsis-h"></i></button>
                                            @endif
                                            <a href="{{url('/admin/complaint/delete/'.$complaint->id)}}" class="text-decoration-none">
                                                <div class="badge badge-danger"><i class="material-icons font_size_14">delete</i></div>
                                            </a>
                                        </td>
                                    </tr>
                                    @endforeach
                                </table>
                            </div>
                        </div>
                        <div class="card-footer text-right">
                            <nav class="d-inline-block">
                                {{$complaints->links('adminDashboard.pagination')}}
                            </nav>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="formModal" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="formModal">Reply to Complaint</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <form method="post" action="{{url('/admin/complaint/reply')}}">
                        @csrf
                        <div class="row">
                            <div class="col-12">
                                <input type="hidden" name="id" value="">
                                <textarea class="form-control" rows="10" name="reply" required></textarea>
                            </div>
                            <div class="col-12 mt-3">
                                <input type="submit" class="btn btn-success">
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

</div>
</div>
@include('adminDashboard.layout.footer')