TA/web_JMW/resources/views/user/cars.blade.php

802 lines
21 KiB
PHP

<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="csrf-token" content="{{ csrf_token() }}" />
<title>Marketplace Mobil Bekas</title>
<style>
:root {
font-family: Inter, system-ui, sans-serif;
color: #111827;
background: #f8fafc;
}
* {
box-sizing: border-box;
}
body {
margin: 0;
background: linear-gradient(180deg, #eef2ff 0%, #f8fafc 100%);
scroll-behavior: smooth;
}
.page-shell {
max-width: 1200px;
margin: 0 auto;
padding: 32px 24px 64px;
}
.hero {
display: grid;
grid-template-columns: minmax(0, 1.5fr) minmax(280px, 1fr);
gap: 24px;
align-items: center;
margin-bottom: 32px;
}
.hero-copy p {
margin-top: 18px;
color: #475569;
line-height: 1.75;
max-width: 720px;
font-size: 1rem;
}
.hero-copy h1 {
margin: 0;
font-size: clamp(2.75rem, 4vw, 3.8rem);
line-height: 1.05;
letter-spacing: -0.04em;
}
.hero-actions {
margin-top: 30px;
display: flex;
flex-wrap: wrap;
gap: 14px;
}
.button-primary,
.button-secondary {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
border: none;
border-radius: 999px;
padding: 14px 24px;
font-weight: 700;
text-decoration: none;
transition: transform 0.2s ease, background 0.2s ease;
cursor: pointer;
}
.button-primary {
background: #4338ca;
color: #ffffff;
box-shadow: 0 18px 40px rgba(67, 56, 202, 0.18);
}
.button-primary:hover {
transform: translateY(-1px);
background: #3730a3;
}
.button-secondary {
background: #ffffff;
color: #4338ca;
border: 1px solid #c7d2fe;
box-shadow: 0 12px 24px rgba(67, 56, 202, 0.08);
}
.button-secondary:hover {
transform: translateY(-1px);
background: #eef2ff;
}
.hero-image {
position: relative;
background: linear-gradient(135deg, #6366f1 0%, #c7d2fe 100%);
border-radius: 32px;
min-height: 340px;
display: grid;
place-items: center;
color: white;
padding: 28px;
box-shadow: 0 30px 90px rgba(15, 23, 42, 0.12);
}
.user-profile-link {
text-decoration: none;
color: inherit;
}
.user-profile {
position: absolute;
top: 18px;
right: 18px;
display: flex;
align-items: center;
gap: 12px;
padding: 8px 12px;
border-radius: 999px;
background: rgba(255, 255, 255, 0.98);
color: #0f172a;
border: 1px solid rgba(148, 163, 184, 0.3);
box-shadow: 0 12px 32px rgba(15, 23, 42, 0.15);
cursor: pointer;
transition: all 0.2s ease;
}
.user-profile:hover {
background: rgba(255, 255, 255, 1);
box-shadow: 0 16px 40px rgba(15, 23, 42, 0.2);
transform: translateY(-1px);
}
.user-profile a {
text-decoration: none;
color: inherit;
}
.profile-dropdown-menu {
display: none;
position: absolute;
top: 70px;
right: 0;
background: white;
border-radius: 16px;
box-shadow: 0 12px 40px rgba(15, 23, 42, 0.15);
border: 1px solid rgba(148, 163, 184, 0.15);
min-width: 200px;
z-index: 1000;
overflow: hidden;
}
.profile-dropdown-menu.active {
display: block;
}
.profile-dropdown-menu a,
.profile-dropdown-menu button {
display: flex;
align-items: center;
gap: 12px;
width: 100%;
padding: 12px 16px;
border: none;
background: none;
color: #0f172a;
text-decoration: none;
cursor: pointer;
font-size: 0.95rem;
font-weight: 500;
transition: background 0.2s ease;
}
.profile-dropdown-menu a:hover,
.profile-dropdown-menu button:hover {
background: #f8fafc;
}
.profile-dropdown-menu button:last-child {
color: #ef4444;
border-top: 1px solid #e5e7eb;
}
.profile-dropdown-menu button:last-child:hover {
background: #fef2f2;
}
.profile-dropdown-menu svg {
width: 18px;
height: 18px;
}
.profile-avatar {
width: 42px;
height: 42px;
border-radius: 50%;
display: grid;
place-items: center;
background: #4338ca;
color: white;
font-weight: 700;
font-size: 0.95rem;
flex-shrink: 0;
box-shadow: 0 4px 12px rgba(67, 56, 202, 0.3);
}
.profile-info {
display: flex;
flex-direction: column;
}
.profile-info span {
display: block;
font-weight: 700;
font-size: 0.95rem;
color: #0f172a;
line-height: 1.2;
}
.profile-info small {
display: block;
color: #64748b;
font-size: 0.78rem;
line-height: 1.2;
}
.hero-image h2 {
margin: 0;
font-size: clamp(1.9rem, 3.5vw, 2.5rem);
line-height: 1.1;
}
.hero-image p {
margin-top: 14px;
max-width: 320px;
color: rgba(255, 255, 255, 0.85);
line-height: 1.7;
}
.filter-panel {
margin-top: -20px;
padding: 24px;
background: #ffffff;
border-radius: 28px;
box-shadow: 0 24px 70px rgba(15, 23, 42, 0.08);
display: grid;
grid-template-columns: 1fr auto;
gap: 20px;
align-items: center;
}
.filter-panel label {
display: block;
margin-bottom: 10px;
font-weight: 700;
color: #111827;
}
.filter-panel input {
width: 100%;
padding: 14px 16px;
border-radius: 16px;
border: 1px solid #d1d5db;
font-size: 1rem;
color: #111827;
}
.section-heading {
display: flex;
justify-content: space-between;
align-items: center;
gap: 16px;
flex-wrap: wrap;
margin: 40px 0 20px;
}
.section-heading h2 {
margin: 0;
font-size: 1.6rem;
}
.section-heading p {
margin: 8px 0 0;
color: #475569;
line-height: 1.7;
}
.section-heading span {
color: #6b7280;
font-size: 0.95rem;
}
.market-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: 12px;
}
.market-slider {
position: relative;
}
.market-slider .market-grid {
grid-auto-flow: column;
grid-auto-columns: calc((100% - 60px) / 6);
grid-template-columns: none;
overflow-x: auto;
scroll-behavior: smooth;
scroll-snap-type: x mandatory;
padding: 2px 4px 16px;
scrollbar-width: none;
}
.market-slider .market-grid::-webkit-scrollbar {
display: none;
}
.market-slider .card-link {
scroll-snap-align: start;
}
.slider-controls {
display: flex;
justify-content: flex-end;
gap: 10px;
margin: -8px 0 14px;
}
.slider-button {
width: 42px;
height: 42px;
border: 1px solid #c7d2fe;
border-radius: 50%;
background: #ffffff;
color: #4338ca;
display: grid;
place-items: center;
font-size: 1.4rem;
font-weight: 800;
line-height: 1;
box-shadow: 0 12px 24px rgba(67, 56, 202, 0.08);
cursor: pointer;
transition: transform 0.2s ease, background 0.2s ease;
}
.slider-button:hover {
transform: translateY(-1px);
background: #eef2ff;
}
.card-link {
display: block;
text-decoration: none;
color: inherit;
}
.card-link:hover .listing-card {
transform: translateY(-3px);
box-shadow: 0 24px 60px rgba(15, 23, 42, 0.1);
}
.listing-card {
background: white;
border-radius: 16px;
border: 1px solid #e5e7eb;
overflow: hidden;
display: flex;
flex-direction: column;
min-height: 100%;
transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.listing-card:hover {
transform: translateY(-3px);
box-shadow: 0 24px 60px rgba(15, 23, 42, 0.1);
}
.listing-image {
position: relative;
min-height: 130px;
width: 100%;
background: #f8fafc;
display: grid;
place-items: center;
color: #0f172a;
text-align: center;
overflow: hidden;
}
.listing-image img {
width: 100%;
height: 100%;
object-fit: cover;
display: block;
transition: transform 0.3s ease;
}
.listing-image:hover img {
transform: scale(1.02);
}
.listing-image::after {
content: "";
position: absolute;
inset: 0;
background: linear-gradient(180deg, rgba(255,255,255,0.2), transparent 60%);
pointer-events: none;
}
.listing-content {
padding: 10px;
display: flex;
flex-direction: column;
gap: 8px;
flex: 1;
}
.listing-top {
display: flex;
justify-content: space-between;
align-items: flex-end;
gap: 6px;
}
.price {
font-size: 0.98rem;
font-weight: 800;
line-height: 1.1;
color: #0f172a;
}
.year {
color: #475569;
font-size: 0.76rem;
font-weight: 600;
}
.listing-content h3 {
margin: 0;
font-size: 0.88rem;
line-height: 1.15;
font-weight: 700;
color: #111827;
overflow: hidden;
display: -webkit-box;
-webkit-line-clamp: 1;
-webkit-box-orient: vertical;
}
.listing-content p {
margin: 0;
color: #475569;
line-height: 1.35;
min-height: 1.8rem;
font-size: 0.78rem;
overflow: hidden;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
}
.listing-footer {
display: flex;
justify-content: flex-start;
}
.date-badge {
color: #475569;
font-size: 0.72rem;
padding: 4px 8px;
border-radius: 12px;
background: #f8fafc;
font-weight: 600;
}
.wishlist-button {
position: absolute;
top: 16px;
right: 16px;
width: 42px;
height: 42px;
border-radius: 50%;
border: none;
background: rgba(255, 255, 255, 0.96);
display: grid;
place-items: center;
box-shadow: 0 10px 24px rgba(15, 23, 42, 0.12);
cursor: pointer;
transition: transform 0.2s ease, background 0.2s ease;
}
.wishlist-button:hover {
transform: translateY(-1px);
background: #ffffff;
}
.wishlist-button svg {
width: 18px;
height: 18px;
fill: #0f172a;
}
.favorite-button {
position: absolute;
top: 12px;
right: 12px;
width: 36px;
height: 36px;
border-radius: 50%;
border: none;
background: rgba(255, 255, 255, 0.9);
display: grid;
place-items: center;
box-shadow: 0 4px 12px rgba(15, 23, 42, 0.15);
cursor: pointer;
transition: all 0.2s ease;
z-index: 10;
}
.favorite-button:hover {
transform: scale(1.1);
background: #ffffff;
}
.favorite-button.favorited svg {
fill: #ef4444;
}
.favorite-button svg {
width: 18px;
height: 18px;
fill: #64748b;
transition: fill 0.2s ease;
}
.badge {
display: inline-flex;
padding: 10px 14px;
border-radius: 999px;
background: #e0f2fe;
color: #0369a1;
font-weight: 700;
font-size: 0.85rem;
}
.empty-state {
grid-column: 1 / -1;
text-align: center;
background: white;
border-radius: 28px;
padding: 48px 32px;
box-shadow: 0 24px 70px rgba(15, 23, 42, 0.08);
margin-top: 24px;
}
.empty-state h2 {
margin: 0;
font-size: 1.75rem;
}
.empty-state p {
margin: 16px 0 0;
color: #6b7280;
line-height: 1.75;
}
@media (max-width: 900px) {
.hero {
grid-template-columns: 1fr;
}
.filter-panel {
grid-template-columns: 1fr;
}
.market-slider .market-grid {
grid-auto-columns: calc((100% - 24px) / 3);
}
}
@media (max-width: 640px) {
.market-slider .market-grid {
grid-auto-columns: calc((100% - 12px) / 2);
}
}
@media (max-width: 420px) {
.market-slider .market-grid {
grid-auto-columns: 86%;
}
}
</style>
</head>
<body>
<div class="page-shell">
<header class="hero">
<div class="hero-copy">
<p style="font-weight:700; color:#4338ca; text-transform:uppercase; letter-spacing:0.18em; margin-bottom:18px;">
{{ Auth::check() ? 'JMW showroom mobil bekas' : 'Pasar Mobil Bekas' }}
</p>
<h1>{{ Auth::check() ? 'Selamat Datang, ' . (Auth::user()->username ?? 'User') : 'Jual Mobil Bekas Lebih Mudah dan Cepat' }}</h1>
<p>{{ Auth::check() ? 'Lihat katalog kendaraan yang tersedia, bandingkan harga dan spesifikasi, serta manfaatkan fitur rekomendasi untuk membantu menentukan pilihan mobil yang sesuai dengan budget Anda.' : 'Telusuri mobil bekas unggulan, bandingkan harga, dan dapatkan rekomendasi sesuai budget Anda.' }}</p>
<div class="hero-actions">
<a href="{{ route('semua-mobil-bekas') }}" class="button-primary">Lihat Semua Mobil</a>
<a href="{{ route('rekomendasi-budget') }}" class="button-secondary">Cari Sesuai Budget</a>
</div>
</div>
<div class="hero-image">
@if(Auth::check())
<div class="user-profile" id="profileButton">
<div class="profile-avatar">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<circle cx="12" cy="8" r="4" fill="white"/>
<path d="M6 20c0-3.314 2.686-6 6-6s6 2.686 6 6" fill="white"/>
</svg>
</div>
<div class="profile-info">
<span>{{ Auth::user()->username ?? 'User' }}</span>
<small>Profil</small>
</div>
</div>
<div class="profile-dropdown-menu" id="profileMenu">
<a href="{{ route('user.profile') }}">
<svg fill="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<circle cx="12" cy="8" r="4" fill="currentColor"/>
<path d="M6 20c0-3.314 2.686-6 6-6s6 2.686 6 6" fill="currentColor"/>
</svg>
Lihat Profil
</a>
<form method="POST" action="{{ route('logout') }}" style="margin: 0;">
@csrf
<button type="submit">
<svg fill="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path d="M17 7l-1.41 1.41L18.17 11H8v2h10.17l-2.58 2.58L17 17l5-5-5-5zM4 5h8V3H4c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h8v-2H4V5z"/>
</svg>
Logout
</button>
</form>
</div>
@else
<div class="user-profile" style="gap: 8px;">
<a href="{{ route('login') }}" class="button-secondary" style="padding: 10px 16px; font-size: 0.9rem; border-radius: 16px;">Login</a>
<a href="{{ route('register') }}" class="button-primary" style="padding: 10px 16px; font-size: 0.9rem; border-radius: 16px;">Register</a>
</div>
@endif
<div>
<h2>Temukan Mobil Bekas Impianmu Sekarang Juga!</h2>
</div>
</div>
</header>
@if($categories->isEmpty())
<div class="empty-state">
<h2>Belum ada listing mobil bekas.</h2>
<p>Silakan tambahkan mobil bekas lewat halaman manajemen kategori agar tampil di marketplace ini.</p>
</div>
@else
<div id="all-cars" class="section-heading">
<div>
<h2>Semua Mobil Bekas</h2>
<p>Lihat semua listing mobil bekas yang tersedia di pasar kami.</p>
</div>
<span>{{ $categories->count() }} listing</span>
</div>
<div class="market-slider" data-slider>
<div class="slider-controls">
<button class="slider-button" type="button" data-slider-prev aria-label="Slide sebelumnya">&lsaquo;</button>
<button class="slider-button" type="button" data-slider-next aria-label="Slide berikutnya">&rsaquo;</button>
</div>
<div class="market-grid" data-slider-track>
@foreach($categories as $category)
<a href="{{ route('mobil-bekas.detail', $category) }}" class="card-link">
<article class="listing-card">
<div class="listing-image">
<img src="{{ $category->image_url }}" alt="{{ $category->image ? $category->name : 'Gambar default ' . $category->name }}" />
@if(Auth::check())
<button class="favorite-button {{ $category->isFavoritedBy(Auth::user()->username) ? 'favorited' : '' }}"
data-category-id="{{ $category->id }}"
type="button">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z"/>
</svg>
</button>
@endif
</div>
<div class="listing-content">
<div class="listing-top">
<div class="price">Rp {{ number_format($category->price, 0, ',', '.') }}</div>
@if($category->year)
<div class="year">{{ $category->year }}</div>
@endif
</div>
<h3>{{ $category->name }}</h3>
<p>{{ \Illuminate\Support\Str::limit($category->description, 60) }}</p>
<div class="listing-footer">
<span class="date-badge">{{ $category->created_at && $category->created_at->isToday() ? 'HARI INI' : $category->created_at->format('d M Y') }}</span>
</div>
</div>
</article>
</a>
@endforeach
</div>
</div>
@endif
</div>
<script>
// Handle profile dropdown
const profileButton = document.getElementById('profileButton');
const profileMenu = document.getElementById('profileMenu');
if (profileButton && profileMenu) {
profileButton.addEventListener('click', function(e) {
e.stopPropagation();
profileMenu.classList.toggle('active');
});
document.addEventListener('click', function(e) {
if (!profileButton.contains(e.target) && !profileMenu.contains(e.target)) {
profileMenu.classList.remove('active');
}
});
}
document.querySelectorAll('[data-slider]').forEach(slider => {
const track = slider.querySelector('[data-slider-track]');
const prevButton = slider.querySelector('[data-slider-prev]');
const nextButton = slider.querySelector('[data-slider-next]');
if (!track || !prevButton || !nextButton) {
return;
}
const scrollSlide = direction => {
track.scrollBy({
left: direction * track.clientWidth,
behavior: 'smooth'
});
};
prevButton.addEventListener('click', () => scrollSlide(-1));
nextButton.addEventListener('click', () => scrollSlide(1));
});
// Handle favorite button clicks
document.addEventListener('DOMContentLoaded', function() {
document.querySelectorAll('.favorite-button').forEach(button => {
button.addEventListener('click', function(e) {
e.preventDefault();
e.stopPropagation();
const categoryId = this.dataset.categoryId;
const isFavorited = this.classList.contains('favorited');
const url = isFavorited
? `/favorites/${categoryId}`
: `/favorites/${categoryId}`;
const method = isFavorited ? 'DELETE' : 'POST';
fetch(url, {
method: method,
headers: {
'Content-Type': 'application/json',
'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]')?.getAttribute('content') || ''
},
body: method === 'POST' ? JSON.stringify({}) : null
})
.then(async response => {
const data = await response.json();
if (!response.ok) {
throw new Error(data.message || 'Gagal memperbarui favorit.');
}
return data;
})
.then(data => {
if (isFavorited) {
this.classList.remove('favorited');
} else {
this.classList.add('favorited');
}
})
.catch(error => {
console.error('Error:', error);
alert(error.message || 'Terjadi kesalahan. Silakan coba lagi.');
});
});
});
});
</script>
</body>
</html>