TIF_NGANJUK_E41220737/resources/views/landing/pesan/show.blade.php

122 lines
5.9 KiB
PHP

@extends('layouts.frontend')
@section('title', 'Chat dengan ' . $lawan->nama_lengkap)
@section('content')
<div class="container py-5">
<div class="row g-0 chat-container">
<div class="col-md-4 chat-sidebar d-none d-md-block">
<div class="p-3 bg-white sticky-top border-bottom">
<input type="text" class="form-control rounded-pill" placeholder="Cari pesan...">
</div>
<div class="list-group list-group-flush">
@foreach ($chatList as $chat)
<a href="{{ route('pembeli.pesan.show', $chat['lawan_id']) }}"
class="list-group-item list-group-item-action chat-list-item py-3 {{ $chat['lawan_id'] == $lawan->id ? 'active' : '' }}">
<div class="d-flex align-items-center">
<img src="{{ asset('template/frontend/img/avatar.jpg') }}" class="rounded-circle"
width="50" height="50" style="object-fit: cover;">
<div class="ms-3 flex-grow-1 overflow-hidden">
<div class="d-flex justify-content-between align-items-center mb-1">
<h6
class="mb-0 fw-bold {{ $chat['lawan_id'] == $lawan->id ? 'text-dark' : 'text-dark' }}">
{{ $chat['nama'] }}</h6>
<small
class="{{ $chat['lawan_id'] == $lawan->id ? 'text-muted' : 'text-muted' }}">{{ $chat['time'] }}</small>
</div>
<p
class="mb-0 small text-truncate {{ $chat['lawan_id'] == $lawan->id ? 'text-dark' : 'text-muted' }}">
{{ Str::limit($chat['last_message'], 30) }}
</p>
</div>
</div>
</a>
@endforeach
</div>
</div>
<div class="col-md-8 chat-content">
{{-- Chat Header --}}
<div class="chat-header d-flex align-items-center bg-white shadow-sm">
<a href="{{ route('pembeli.pesan.index') }}" class="d-md-none me-3 text-dark">
<i class="fas fa-arrow-left"></i>
</a>
<div class="bg-success text-white rounded-circle d-flex align-items-center justify-content-center fw-bold me-3"
style="width: 45px; height: 45px;">
{{ substr($lawan->nama_lengkap, 0, 1) }}
</div>
<div>
<h6 class="mb-0 fw-bold text-dark">{{ $lawan->nama_lengkap }}</h6>
<small class="text-success"><i class="fas fa-store me-1"></i>{{ $lawan->nama_usaha }}</small>
</div>
</div>
{{-- Chat Box --}}
<div class="chat-box" id="chatBox">
@forelse ($chats as $chat)
@php
$isMe =
$chat->pengirim_id == Auth::guard('pembeli')->id() &&
$chat->pengirim_type == 'App\Models\Pembeli';
@endphp
<div class="d-flex {{ $isMe ? 'justify-content-end' : 'justify-content-start' }} mb-3">
<div class="message-bubble shadow-sm {{ $isMe ? 'message-me' : 'message-other' }}">
<div>{{ $chat->isi_pesan }}</div>
<div class="text-end mt-1" style="font-size: 0.65rem; opacity: 0.8;">
{{ $chat->created_at->format('H:i') }}
@if ($isMe)
<i class="fas fa-check-double ms-1"></i>
@endif
</div>
</div>
</div>
@empty
<div class="text-center py-5 mt-5">
<p class="text-muted bg-white d-inline-block px-3 py-1 rounded-pill border">Mulai percakapan
dengan {{ $lawan->nama_lengkap }}</p>
</div>
@endforelse
</div>
{{-- Footer Chat --}}
<div class="chat-footer">
<form action="{{ route('pesan.kirim') }}" method="POST" class="d-flex gap-2">
@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 rounded-pill border-success"
placeholder="Ketik pesan..." required autocomplete="off">
<button type="submit"
class="btn btn-success rounded-circle d-flex align-items-center justify-content-center"
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;
}
// Fokus ke input
$('input[name="isi_pesan"]').focus();
});
</script>
@endsection