262 lines
9.8 KiB
PHP
262 lines
9.8 KiB
PHP
@extends('layouts.frontend')
|
|
@section('title', 'Chat dengan ' . $lawan->nama_lengkap)
|
|
|
|
@section('content')
|
|
<style>
|
|
.chat-layout {
|
|
height: 80vh;
|
|
background-color: #fff;
|
|
border: 1px solid #e9ecef;
|
|
border-radius: 12px;
|
|
overflow: hidden;
|
|
}
|
|
|
|
/* --- Sidebar Kiri (List User) --- */
|
|
.chat-sidebar {
|
|
background-color: #fff;
|
|
border-right: 1px solid #f0f0f0;
|
|
height: 100%;
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
|
|
.chat-item {
|
|
transition: all 0.2s;
|
|
border-bottom: 1px solid #f8f9fa;
|
|
}
|
|
|
|
.chat-item:hover,
|
|
.chat-item.active {
|
|
background-color: #f9fdf0;
|
|
border-left: 4px solid #81c408;
|
|
}
|
|
|
|
/* --- Area Chat Kanan --- */
|
|
.chat-main {
|
|
background-color: #ffffff;
|
|
display: flex;
|
|
flex-direction: column;
|
|
height: 100%;
|
|
}
|
|
|
|
.chat-header {
|
|
padding: 15px 20px;
|
|
background: #fff;
|
|
border-bottom: 1px solid #f0f0f0;
|
|
}
|
|
|
|
.chat-content {
|
|
flex-grow: 1;
|
|
overflow-y: auto;
|
|
padding: 25px;
|
|
background-color: #fafafa;
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 15px;
|
|
}
|
|
|
|
/* --- Bubble Chat Style --- */
|
|
.chat-bubble {
|
|
max-width: 75%;
|
|
padding: 12px 18px;
|
|
position: relative;
|
|
font-size: 0.95rem;
|
|
line-height: 1.5;
|
|
border-radius: 18px;
|
|
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.03);
|
|
}
|
|
|
|
/* Pesan SAYA */
|
|
.bubble-me {
|
|
background-color: #81c408;
|
|
color: #ffffff;
|
|
align-self: flex-end;
|
|
border-bottom-right-radius: 4px;
|
|
}
|
|
|
|
/* Pesan LAWAN */
|
|
.bubble-other {
|
|
background-color: #f1f3f5;
|
|
color: #333333;
|
|
align-self: flex-start;
|
|
border-bottom-left-radius: 4px;
|
|
}
|
|
|
|
.chat-time {
|
|
font-size: 0.7rem;
|
|
margin-top: 4px;
|
|
display: block;
|
|
text-align: right;
|
|
opacity: 0.7;
|
|
}
|
|
|
|
.chat-footer {
|
|
padding: 15px 20px;
|
|
background: #fff;
|
|
border-top: 1px solid #f0f0f0;
|
|
}
|
|
|
|
.btn-send {
|
|
background-color: #81c408;
|
|
color: white;
|
|
border: none;
|
|
transition: 0.3s;
|
|
}
|
|
|
|
.btn-send:hover {
|
|
background-color: #6da705;
|
|
color: white;
|
|
}
|
|
|
|
::-webkit-scrollbar {
|
|
width: 5px;
|
|
}
|
|
|
|
::-webkit-scrollbar-track {
|
|
background: transparent;
|
|
}
|
|
|
|
::-webkit-scrollbar-thumb {
|
|
background: #ddd;
|
|
border-radius: 10px;
|
|
}
|
|
</style>
|
|
|
|
<div class="container py-5">
|
|
<div class="row g-0 chat-layout shadow-sm">
|
|
|
|
{{-- SIDEBAR KIRI --}}
|
|
<div class="col-md-4 chat-sidebar d-none d-md-flex">
|
|
{{-- Header Sidebar --}}
|
|
<div class="p-3 border-bottom">
|
|
<h6 class="fw-bold text-dark mb-3">Pesan Masuk</h6>
|
|
<input type="text" class="form-control bg-light border-0 rounded-pill" placeholder="Cari percakapan...">
|
|
</div>
|
|
|
|
{{-- List Chat --}}
|
|
<div class="flex-grow-1 overflow-auto">
|
|
@foreach ($chatList as $chat)
|
|
<a href="{{ route('pembeli.pesan.show', $chat['lawan_id']) }}"
|
|
class="d-flex align-items-center p-3 text-decoration-none text-dark chat-item {{ $chat['lawan_id'] == $lawan->id ? 'active' : '' }}">
|
|
|
|
{{-- Avatar --}}
|
|
<div class="position-relative">
|
|
<img src="{{ asset('template/frontend/img/avatar.jpg') }}" class="rounded-circle" width="45"
|
|
height="45" style="object-fit: cover;">
|
|
@if($chat['unread'] > 0)
|
|
<span
|
|
class="position-absolute top-0 start-100 translate-middle p-1 bg-danger border border-light rounded-circle"></span>
|
|
@endif
|
|
</div>
|
|
|
|
<div class="ms-3 flex-grow-1 overflow-hidden">
|
|
<div class="d-flex justify-content-between align-items-center">
|
|
<span class="fw-bold small">{{ $chat['nama'] }}</span>
|
|
<span class="text-muted" style="font-size: 0.7rem;">{{ $chat['time'] }}</span>
|
|
</div>
|
|
<div class="d-flex justify-content-between align-items-center mt-1">
|
|
<p class="mb-0 text-muted small text-truncate" style="max-width: 85%;">
|
|
{{ Str::limit($chat['last_message'], 25) }}
|
|
</p>
|
|
@if($chat['unread'] > 0)
|
|
<span class="badge bg-danger rounded-pill"
|
|
style="font-size: 0.6rem;">{{ $chat['unread'] }}</span>
|
|
@endif
|
|
</div>
|
|
</div>
|
|
</a>
|
|
@endforeach
|
|
</div>
|
|
</div>
|
|
|
|
{{-- AREA CHAT KANAN --}}
|
|
<div class="col-md-8 chat-main">
|
|
|
|
{{-- Header Chat --}}
|
|
<div class="chat-header d-flex align-items-center justify-content-between">
|
|
<div class="d-flex align-items-center">
|
|
<a href="{{ route('pembeli.pesan.index') }}" class="d-md-none me-3 text-dark"><i
|
|
class="fas fa-arrow-left"></i></a>
|
|
|
|
{{-- Inisial Nama Lawan --}}
|
|
<div class="rounded-circle d-flex align-items-center justify-content-center fw-bold text-white me-3"
|
|
style="width: 40px; height: 40px; background-color: #81c408; font-size: 1.1rem;">
|
|
{{ substr($lawan->nama_lengkap, 0, 1) }}
|
|
</div>
|
|
|
|
<div>
|
|
<h6 class="mb-0 fw-bold" style="color: #333;">{{ $lawan->nama_lengkap }}</h6>
|
|
<small class="text-muted" style="font-size: 0.8rem;">
|
|
<i class="fas fa-store me-1 text-success"></i> {{ $lawan->nama_usaha ?? 'Online' }}
|
|
</small>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{{-- Isi Pesan (Chat Box) --}}
|
|
<div class="chat-content" id="chatBox">
|
|
@php
|
|
$currentUser = Auth::guard('petani')->check() ? Auth::guard('petani')->user() : Auth::guard('pembeli')->user();
|
|
$currentUserType = get_class($currentUser);
|
|
@endphp
|
|
|
|
@forelse ($chats as $chat)
|
|
@php
|
|
$isMe = ($chat->pengirim_id == $currentUser->id) && ($chat->pengirim_type == $currentUserType);
|
|
@endphp
|
|
|
|
{{-- BUBBLE CHAT --}}
|
|
<div class="chat-bubble {{ $isMe ? 'bubble-me' : 'bubble-other' }}">
|
|
{{ $chat->isi_pesan }}
|
|
<span class="chat-time">
|
|
{{ $chat->created_at->format('H:i') }}
|
|
@if ($isMe)
|
|
<i class="fas fa-check ms-1" style="font-size: 0.6rem;"></i>
|
|
@endif
|
|
</span>
|
|
</div>
|
|
|
|
@empty
|
|
<div class="text-center mt-5 opacity-50">
|
|
<i class="far fa-comments fa-3x mb-3 text-secondary"></i>
|
|
<p class="small text-muted">Belum ada percakapan.<br>Sapa
|
|
<strong>{{ $lawan->nama_lengkap }}</strong> sekarang!</p>
|
|
</div>
|
|
@endforelse
|
|
</div>
|
|
|
|
{{-- Input Footer --}}
|
|
<div class="chat-footer">
|
|
<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 }}">
|
|
<input type="hidden" name="penerima_type" value="{{ get_class($lawan) }}">
|
|
|
|
<input type="text" name="isi_pesan" class="form-control bg-light border-0 rounded-pill px-4 py-2"
|
|
placeholder="Tulis pesan Anda..." required autocomplete="off">
|
|
|
|
<button type="submit"
|
|
class="btn btn-send rounded-circle d-flex align-items-center justify-content-center shadow-sm"
|
|
style="width: 45px; height: 45px;">
|
|
<i class="fas fa-paper-plane"></i>
|
|
</button>
|
|
</form>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
@endsection
|
|
|
|
@section('js')
|
|
<script>
|
|
$(document).ready(function () {
|
|
// Auto scroll ke bawah
|
|
const chatBox = document.getElementById("chatBox");
|
|
if (chatBox) {
|
|
chatBox.scrollTop = chatBox.scrollHeight;
|
|
}
|
|
$('input[name="isi_pesan"]').focus();
|
|
});
|
|
</script>
|
|
@endsection |