@section('css')
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css" />
@endsection
<div class="container-xxl flex-grow-1 container-p-y chat_screen">
    <div class="row mx-1 my-1">
        <div class="col-md-4">
            <h4 class="fw-bold py-3 mb-4">Chat <span class="text-muted fw-light">/ Detail</span></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>
    <div class="row mx-1 my-1">
        <div class="card">
            <div class="card-body">
                <div class="chat_screen">
                    <div class="box">
                        <div class="row">
                            
                            <div class="col-lg-12">
                                <div class="message_base_parent">
                                    <div class="message_box_inner">
                                
                                        <div class="top_box_inner position-relative">
                                            <div class="users_chat_list_box_cselem active">
                                                <div class="row">
                                                    <div class="name-bx-pr-cslem col-8">
                                                        <h5>{{$chat->company_one->name ?? ""}} <span style="font-size: 10px">vs</span> {{$chat->company_two->name ?? ""}}</h5>
                                                    </div>
                                                    <div class="col-4 d-flex justify-content-end">
                                                        <a href="{{route('admin.reports.chatDetail', $chat->id)}}" class="btn btn-primary" style="color: white"><strong>Export</strong></a>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                
                                        <div class="chat_wrapper_inner">
                                            
                                            @forelse($chat->messages as $msg)
                                                <div class="message_box_chat_inner {{($msg->sender_id == $chat->company_one->id) ? 'float-end sent_message' : 'float-start recieve_message' }}">
                                                    <span><strong style="color: black">{{$msg->sender->name ?? ""}}</strong></span>
                                                    @if($msg->type == 'TEXT')
                                                        <p>{{$msg->message}}</p>
                                                    @else
                                                        @php $ext = Illuminate\Support\Str::afterLast($msg->file_path, '.') @endphp
                                                        @if(in_array(Str::lower($ext), ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp', 'svg']))
                                                            <img src="{{ $msg->file_path }}" class="chat-media"/>
                                                        @else
                                                            <p><a href="{{$msg->file_path ?? "javscript:;"}}" download>{{Illuminate\Support\Str::afterLast($msg->file_path, '/')}}</a></p>
                                                        @endif
                                                    @endif
                                                    <span>{{$msg->created_at->format('Y-m-d H:i')}}</span>
                                                </div>
                                            @empty
                                                <div class="message_box_chat_inner">
                                                    <p style="text-align: center"><strong>No record found</strong></p>
                                                </div>
                                            @endforelse
                                            
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </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