@section('css')
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css" />
@endsection

<div>
    <div class="row">
        <div class="col-md-4 d-flex justify-content-between mt-2 mb-2">
            <h4 class="fw-bold "><span class="text-muted fw-light"></span> Chat List</h4>
        </div>

        <div class="col-md-8 d-flex justify-content-end">
            <div class="row col-12">
                <div class="col-6">
                    <input type="text" name="datefilter" value="" class="form-control" placeholder="Date Range"/>
                </div>
                <div class="col-6">
                    <input type="text" wire:model.live.debounce.300ms="search" value="" name="search" placeholder="Search" class="form-control search">
                </div>
            </div>
            
        </div>
    </div>
    <!-- Striped Rows -->
    <div class="card">
        <div class="card-body">
            
            <div class="table-responsive text-wrap">
                <table class="table table-hover">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>Participants</th>
                        <th>Messages Count</th>
                        <th>Action</th>
                    </tr>
                </thead>
                <tbody class="table-border-bottom-0">
                    @forelse ($chatList as $chat)
                        @if($chat->company_one && $chat->company_two)
                            <tr>
                                <td>{{$chat->id}}</td>
                                <td>{{$chat->company_one->name ?? ""}} <span style="font-size: 10px">vs</span> {{$chat->company_two->name ?? ""}}</td>
                                <td>{{$chat->msg_count ?? 0}}</td>
                                <td><a href="{{url('admin/chat/detail/' . $chat->id)}}" title="View Detail">
                                    <i class="bx bx-show btn btn-primary btn-xs"></i></td>
                            </tr>
                        @endif
                    @empty
                        <tr>
                            <td colspan="5" class="text-center">No record found</td>
                        </tr>
                    @endforelse
                </tbody>
                </table>
                <div>
                    {{ $chatList->links('livewire.pagination') }}
                </div>
            </div>
        </div>
    </div>
</div>

@section('script')
<script type="text/javascript" src="https://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script>
<script type="text/javascript">
    $(function() {
    
      $('input[name="datefilter"]').daterangepicker({
          autoUpdateInput: false,
          locale: {
              cancelLabel: 'Clear'
          }
      });
    
      $('input[name="datefilter"]').on('apply.daterangepicker', function(ev, picker) {
          $(this).val(picker.startDate.format('YYYY-MM-DD') + ' - ' + picker.endDate.format('YYYY-MM-DD'));
          @this.set('dateRange', $(this).val());
      });
    
      $('input[name="datefilter"]').on('cancel.daterangepicker', function(ev, picker) {
          $(this).val('');
          @this.set('dateRange','');
      });
    
    });
    </script>
@endsection