145 lines
7.6 KiB
PHP
145 lines
7.6 KiB
PHP
@extends('layouts.admin')
|
|
@section('title', 'Chat: ' . $lawan->nama_lengkap)
|
|
|
|
@section('content')
|
|
<section class="section">
|
|
<div class="card chat-card shadow-sm">
|
|
<div class="row g-0 h-100">
|
|
|
|
<div class="col-md-4 chat-sidebar d-none d-md-block">
|
|
<div class="p-4 border-bottom bg-white sticky-top">
|
|
<h5 class="mb-3 text-primary"><i class="bi bi-chat-left-text-fill"></i> Percakapan</h5>
|
|
<div class="form-group position-relative has-icon-right mb-0">
|
|
<input type="text" class="form-control" placeholder="Cari pembeli...">
|
|
<div class="form-control-icon">
|
|
<i class="bi bi-search"></i>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="list-group list-group-flush">
|
|
@foreach ($chatList as $chat)
|
|
<a href="{{ route('petani.pesan.show', $chat['lawan_id']) }}"
|
|
class="list-group-item list-group-item-action chat-item p-3 {{ $chat['lawan_id'] == $lawan->id ? 'active' : '' }}">
|
|
<div class="d-flex align-items-center">
|
|
|
|
<div class="avatar avatar-lg me-3">
|
|
<span class="avatar-content bg-primary text-white">
|
|
{{ substr($chat['nama'], 0, 1) }}
|
|
</span>
|
|
@if ($chat['unread'] > 0)
|
|
<span class="avatar-status bg-danger"></span>
|
|
@endif
|
|
</div>
|
|
|
|
<div class="flex-grow-1 text-truncate">
|
|
<div class="d-flex justify-content-between align-items-center mb-1">
|
|
<h6
|
|
class="mb-0 {{ $chat['lawan_id'] == $lawan->id ? 'text-white' : 'text-dark' }}">
|
|
{{ $chat['nama'] }}
|
|
</h6>
|
|
<small
|
|
class="{{ $chat['lawan_id'] == $lawan->id ? 'text-white' : 'text-muted' }}"
|
|
style="font-size: 11px">{{ $chat['time'] }}</small>
|
|
</div>
|
|
<p
|
|
class="mb-0 small text-truncate {{ $chat['lawan_id'] == $lawan->id ? 'text-white' : 'text-muted' }}">
|
|
{{ Str::limit($chat['last_message'], 30) }}
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</a>
|
|
@endforeach
|
|
</div>
|
|
</div>
|
|
|
|
<div class="col-md-8 chat-window">
|
|
|
|
<div class="p-3 border-bottom bg-white d-flex align-items-center shadow-sm z-index-1">
|
|
<a href="{{ route('petani.pesan.index') }}"
|
|
class="btn btn-sm btn-light me-3 d-md-none rounded-circle">
|
|
<i class="bi bi-arrow-left"></i>
|
|
</a>
|
|
|
|
<div class="avatar avatar-md me-3">
|
|
<div class="avatar-content bg-primary text-white font-bold">
|
|
{{ substr($lawan->nama_lengkap, 0, 1) }}
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<h6 class="mb-0 text-dark">{{ $lawan->nama_lengkap }}</h6>
|
|
<small class="text-muted">{{ $lawan->role ?? 'Pembeli' }}</small>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="chat-content" id="chatContainer">
|
|
@forelse($chats as $chat)
|
|
@php
|
|
$isMe =
|
|
$chat->pengirim_id == Auth::guard('petani')->id() &&
|
|
$chat->pengirim_type == 'App\Models\Petani';
|
|
@endphp
|
|
|
|
<div class="d-flex w-100 mb-3 {{ $isMe ? 'justify-content-end' : 'justify-content-start' }}">
|
|
<div style="max-width: 70%;">
|
|
<div class="p-3 shadow-sm position-relative"
|
|
style="border-radius: 15px;
|
|
border-{{ $isMe ? 'bottom-right' : 'bottom-left' }}-radius: 0;
|
|
background-color: {{ $isMe ? '#435ebe' : '#ffffff' }};
|
|
color: {{ $isMe ? '#ffffff' : '#212529' }};">
|
|
|
|
<p class="mb-1" style="font-size: 0.95rem; line-height: 1.5;">
|
|
{{ $chat->isi_pesan }}
|
|
</p>
|
|
|
|
<div class="d-flex justify-content-end align-items-center mt-1">
|
|
<small style="font-size: 0.7rem; opacity: 0.8; margin-right: 4px;">
|
|
{{ $chat->created_at->format('H:i') }}
|
|
</small>
|
|
@if ($isMe)
|
|
<i class="bi {{ $chat->sudah_dibaca ? 'bi-check-all text-info' : 'bi-check' }}"
|
|
style="font-size: 0.9rem;"></i>
|
|
@endif
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
@empty
|
|
<div class="text-center my-5">
|
|
<span class="badge bg-light-secondary text-secondary p-3 rounded-pill">
|
|
Belum ada percakapan. Sapa pembeli Anda! 👋
|
|
</span>
|
|
</div>
|
|
@endforelse
|
|
</div>
|
|
|
|
<div class="p-3 bg-white border-top">
|
|
<form action="{{ route('pesan.kirim') }}" method="POST" class="d-flex gap-2 align-items-center">
|
|
@csrf
|
|
<input type="hidden" name="penerima_id" value="{{ $lawan->id }}">
|
|
|
|
<div class="input-group">
|
|
<input type="text" name="isi_pesan" class="form-control" placeholder="Ketik pesan..."
|
|
required autocomplete="off">
|
|
<button type="submit" class="btn btn-primary">
|
|
<i class="bi bi-send-fill"></i> Kirim
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
<script>
|
|
document.addEventListener("DOMContentLoaded", function() {
|
|
var chatBox = document.getElementById("chatContainer");
|
|
if (chatBox) {
|
|
chatBox.scrollTop = chatBox.scrollHeight;
|
|
}
|
|
});
|
|
</script>
|
|
@endsection
|