Files

210 lines
12 KiB
PHP

@extends('layouts.app')
@section('title', 'Pemeriksaan Pra-Harian (P2H) Heavy Equipment')
@section('content')
<div class="w-full space-y-6">
<!-- Header Halaman Simple Kayak Satpam (Seamless, Tanpa Card Wrapper) -->
<div class="flex flex-col sm:flex-row sm:items-center justify-between gap-3 pb-3 border-b border-slate-200/80">
<div class="min-w-0">
<div class="flex items-center flex-wrap gap-2.5">
<h1 class="text-lg sm:text-xl font-black text-slate-900 tracking-tight">
Katalog Pemeriksaan Pra-Harian (P2H)
</h1>
<span class="px-2.5 py-1 rounded-lg text-xs font-black bg-amber-50 text-amber-800 border border-amber-200">
Heavy Equipment
</span>
</div>
<div class="text-sm sm:text-base text-slate-600 font-medium truncate mt-1 flex items-center flex-wrap gap-1.5">
<span>Operator: <strong class="text-slate-900 font-bold">{{ $employee ? $employee->name : auth()->user()->name }}</strong></span>
@if($employee && $employee->nik)
<span class="text-slate-500 font-mono text-xs sm:text-sm font-semibold">({{ $employee->nik }})</span>
@endif
@if($employee && $employee->hasValidSimper())
<span class="inline-flex items-center text-[10px] font-bold text-emerald-700 bg-emerald-100/80 px-2 py-0.5 rounded-md ml-1">
<i class="fa-solid fa-circle-check mr-1 text-emerald-600"></i> SIMPER Aktif
</span>
@elseif($employee)
<span class="inline-flex items-center text-[10px] font-bold text-rose-700 bg-rose-100/80 px-2 py-0.5 rounded-md ml-1">
<i class="fa-solid fa-circle-xmark mr-1 text-rose-600"></i> SIMPER Exp
</span>
@endif
</div>
</div>
</div>
<!-- Filter & Search Bar (Tanpa Card Wrapper, Format Referensi Data Karyawan) -->
<form method="GET" action="{{ route('p2h.index') }}" id="p2hFilterForm" class="flex flex-col sm:flex-row items-stretch sm:items-center justify-between gap-2.5 sm:gap-3">
<!-- Pencarian Cepat di Kiri dengan Tombol Cari -->
<div class="relative w-full sm:max-w-md flex items-center">
<span class="absolute inset-y-0 left-0 pl-3.5 flex items-center pointer-events-none text-slate-400 z-10">
<i class="fa-solid fa-magnifying-glass text-xs"></i>
</span>
<input type="text"
name="search"
id="p2hSearchInput"
value="{{ request('search') }}"
placeholder="Cari kode unit (EX01), model, atau lokasi..."
autocomplete="off"
class="w-full text-xs pl-10 pr-20 py-2.5 rounded-xl border border-slate-200 bg-white text-slate-800 placeholder-slate-400 focus:outline-none focus:border-[#1b5e20] focus:ring-2 focus:ring-[#1b5e20]/10 shadow-sm transition">
<button type="submit"
id="p2hSearchBtn"
class="absolute right-1.5 inset-y-1.5 px-3 bg-[#1b5e20] hover:bg-[#144918] active:scale-95 text-white font-bold text-xs rounded-lg flex items-center gap-1.5 transition shadow-sm cursor-pointer z-10">
<span>Cari</span>
</button>
</div>
<!-- Filter Dropdown & Tombol di Kanan -->
<div class="flex flex-col sm:flex-row items-stretch sm:items-center justify-end gap-2 sm:gap-2.5 w-full sm:w-auto">
<div class="w-full sm:w-auto">
<select name="unit_category"
id="p2hCategorySelect"
onchange="this.form.submit()"
class="w-full sm:w-auto text-xs rounded-xl border border-slate-200 bg-white px-3 py-2.5 text-slate-700 font-semibold focus:outline-none focus:border-[#1b5e20] focus:ring-2 focus:ring-[#1b5e20]/10 shadow-sm transition truncate">
<option value="">Semua Kategori Alat</option>
@foreach($categories as $cat)
<option value="{{ $cat }}" {{ request('unit_category') == $cat ? 'selected' : '' }}>{{ $cat }}</option>
@endforeach
</select>
</div>
<!-- Tombol Reset Filter (Merah / Rose Clean Text Persis Halaman Karyawan) -->
<div id="p2hResetContainer">
@if(request()->anyFilled(['search', 'unit_category']))
<a href="{{ route('p2h.index') }}"
id="p2hResetBtn"
class="text-xs text-rose-600 hover:text-rose-700 font-semibold flex items-center justify-center sm:justify-start space-x-1.5 transition whitespace-nowrap py-1 sm:py-0 sm:ml-2">
<i class="fa-solid fa-rotate-left text-[11px]"></i>
<span>Reset Filter</span>
</a>
@endif
</div>
</div>
</form>
<!-- Grid Kartu Heavy Equipment -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4" id="p2hCardsContainer">
@forelse($vehicles as $v)
<div class="p2h-card bg-white rounded-2xl border border-slate-200 shadow-sm hover:shadow-md transition p-5 flex flex-col justify-between">
<div>
<!-- Badge Kategori & Status -->
<div class="flex items-center justify-between mb-3">
<span class="inline-flex items-center px-2.5 py-1 rounded-lg text-[11px] font-bold bg-amber-50 text-amber-800 border border-amber-200">
{{ $v->unit_category ?? 'Heavy Equipment' }}
</span>
@php
$statusBadge = match($v->status) {
'Operation' => 'bg-emerald-50 text-emerald-700 border-emerald-200',
'Standby' => 'bg-amber-50 text-amber-700 border-amber-200',
'Breakdown' => 'bg-rose-50 text-rose-700 border-rose-200',
default => 'bg-slate-50 text-slate-700 border-slate-200',
};
@endphp
<span class="inline-flex items-center px-2 py-0.5 rounded-full text-[10px] font-bold border {{ $statusBadge }}">
{{ $v->status }}
</span>
</div>
<!-- Kode & Tipe Unit -->
<h3 class="text-lg font-black text-slate-900 leading-tight">{{ $v->code }}</h3>
<p class="text-xs text-slate-600 font-medium mt-0.5 line-clamp-1">{{ $v->brand_type }}</p>
<!-- Info Atribut -->
<div class="mt-4 space-y-1.5 text-xs text-slate-500 bg-slate-50 p-3 rounded-xl border border-slate-100">
<div class="flex items-center justify-between">
<span class="text-slate-400">Hour Meter (HM):</span>
<span class="font-extrabold text-slate-800">{{ number_format($v->current_km, 1, ',', '.') }} HM</span>
</div>
<div class="flex items-center justify-between">
<span class="text-slate-400">Lokasi Operasional:</span>
<span class="font-semibold text-slate-700 truncate max-w-[150px]">{{ $v->location ?? '-' }}</span>
</div>
<div class="flex items-center justify-between">
<span class="text-slate-400">Checksheet P2H:</span>
<span class="font-bold text-[#1b5e20] truncate max-w-[150px]">
{{ $v->p2hTemplate ? $v->p2hTemplate->name : ($v->unit_category ?? 'Standar') }}
</span>
</div>
</div>
</div>
<!-- Tombol Buka Form P2H -->
<div class="mt-5 pt-3 border-t border-slate-100">
<a href="{{ route('p2h.form', ['code' => $v->code]) }}" class="w-full bg-[#1b5e20] hover:bg-[#144918] active:scale-[0.99] text-white font-bold py-2.5 px-4 rounded-xl shadow-sm transition text-center block text-xs">
Isi Formulir P2H Unit
</a>
</div>
</div>
@empty
<div id="p2hServerEmptyCard" class="col-span-full bg-white rounded-2xl border border-slate-200 p-12 text-center">
<div class="w-16 h-16 rounded-full bg-slate-100 text-slate-400 flex items-center justify-center mx-auto mb-3">
<i class="fa-solid fa-magnifying-glass text-2xl"></i>
</div>
@if(request('search'))
<h3 class="text-base font-bold text-slate-800">
Data "<span class="text-rose-600 font-bold">{{ request('search') }}</span>" tidak ditemukan di tabel
</h3>
<p class="text-xs text-slate-500 mt-1">Pastikan kode unit atau kategori alat berat yang dicari sudah benar.</p>
<div class="mt-4">
<a href="{{ route('p2h.index') }}" class="inline-flex items-center space-x-1.5 px-3.5 py-2 rounded-xl text-xs font-semibold text-rose-600 bg-rose-50 border border-rose-200 hover:bg-rose-100 transition cursor-pointer">
<i class="fa-solid fa-rotate-left text-[11px]"></i>
<span>Hapus Pencarian</span>
</a>
</div>
@else
<h3 class="text-base font-bold text-slate-800">Heavy Equipment Tidak Ditemukan</h3>
<p class="text-xs text-slate-500 mt-1">Coba sesuaikan kata kunci pencarian atau filter kategori alat berat Anda.</p>
@endif
</div>
@endforelse
</div>
<!-- Pagination -->
@if($vehicles->hasPages())
<div class="bg-white p-4 rounded-2xl border border-slate-200 shadow-sm" id="p2hPaginationContainer">
{{ $vehicles->links() }}
</div>
@endif
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
// Search Server-Side dengan Debounce Pintar & Submit Cepat
const searchInput = document.getElementById('p2hSearchInput');
const filterForm = document.getElementById('p2hFilterForm');
const hasServerSearch = {{ request()->filled('search') ? 'true' : 'false' }};
let debounceTimer = null;
// Otomatis cari ke seluruh database server setelah jeda mengetik 550ms
searchInput?.addEventListener('input', function(e) {
clearTimeout(debounceTimer);
const val = e.target.value.trim();
// Jika input dikosongkan setelah sebelumnya ada pencarian, langsung reload reset
if (val === '' && hasServerSearch) {
debounceTimer = setTimeout(() => {
filterForm.submit();
}, 300);
return;
}
// Auto submit setelah berhenti mengetik minimal 2 karakter
if (val.length >= 2) {
debounceTimer = setTimeout(() => {
filterForm.submit();
}, 550);
}
});
// Submit langsung seketika saat tombol Enter ditekan di keyboard
searchInput?.addEventListener('keydown', function(e) {
if (e.key === 'Enter') {
clearTimeout(debounceTimer);
filterForm.submit();
}
});
});
</script>
@endsection