@extends('layouts.app')
@section('title', 'Installation')
@section('breadcrumb')<span class="text-white">Installation</span>@endsection

@section('content')
<div class="space-y-5">
    <div class="flex items-center justify-between">
        <div><h1>Installation</h1><p>Manage on-site cabinet installation schedules and progress</p></div>
        <a href="{{ route('installation.create') }}" class="btn btn-primary"><i class="fas fa-plus mr-1"></i> Schedule Installation</a>
    </div>

    <div class="card overflow-hidden">
        <div class="overflow-x-auto">
            <table class="w-full">
                <thead>
                    <tr class="text-xs text-slate-500 border-b border-slate-700" style="background: #0f172a;">
                        <th class="text-left px-4 py-3 font-medium">Job</th>
                        <th class="text-left px-4 py-3 font-medium">Client</th>
                        <th class="text-left px-4 py-3 font-medium">Lead Installer</th>
                        <th class="text-left px-4 py-3 font-medium">Start Date</th>
                        <th class="text-left px-4 py-3 font-medium">Est. Completion</th>
                        <th class="text-left px-4 py-3 font-medium">Status</th>
                        <th class="text-left px-4 py-3 font-medium">Progress</th>
                        <th class="px-4 py-3"></th>
                    </tr>
                </thead>
                <tbody>
                    @forelse($installations as $installation)
                    <tr class="table-row" onclick="window.location='{{ route('installation.show', $installation) }}'">
                        <td class="px-4 py-3">
                            <div class="text-sm font-medium text-white">{{ $installation->job?->job_number ?? '—' }}</div>
                            <div class="text-xs text-slate-500">{{ $installation->job?->project_type ? ucfirst($installation->job->project_type) : '' }}</div>
                        </td>
                        <td class="px-4 py-3 text-sm text-white">{{ $installation->job?->contact?->full_name ?? '—' }}</td>
                        <td class="px-4 py-3 text-sm text-slate-300">{{ $installation->leadInstaller?->name ?? '—' }}</td>
                        <td class="px-4 py-3 text-sm text-white">{{ $installation->start_date?->format('d M Y') ?? '—' }}</td>
                        <td class="px-4 py-3 text-sm text-slate-400">{{ $installation->estimated_completion?->format('d M Y') ?? '—' }}</td>
                        <td class="px-4 py-3">
                            @php $sc = match($installation->status) { 'scheduled' => 'blue', 'in_progress' => 'yellow', 'completed' => 'green', 'on_hold' => 'orange', default => 'gray' }; @endphp
                            <span class="badge badge-{{ $sc }}">{{ ucwords(str_replace('_', ' ', $installation->status)) }}</span>
                        </td>
                        <td class="px-4 py-3" style="min-width: 120px;">
                            <div class="progress-bar w-24"><div class="progress-fill" style="width: {{ $installation->progress_pct ?? 0 }}%"></div></div>
                            <div class="text-xs text-slate-500 mt-1">{{ $installation->progress_pct ?? 0 }}%</div>
                        </td>
                        <td class="px-4 py-3" onclick="event.stopPropagation()">
                            <a href="{{ route('installation.show', $installation) }}" class="w-7 h-7 rounded flex items-center justify-center hover:bg-slate-700 text-slate-400 hover:text-white">
                                <i class="fas fa-eye text-xs"></i>
                            </a>
                        </td>
                    </tr>
                    @empty
                    <tr><td colspan="8" class="px-4 py-12 text-center text-slate-500">
                        <i class="fas fa-tools text-3xl mb-3 text-slate-700 block"></i>No installations found.
                    </td></tr>
                    @endforelse
                </tbody>
            </table>
        </div>
        @if($installations->hasPages())
        <div class="px-4 py-3 border-t border-slate-700">{{ $installations->links() }}</div>
        @endif
    </div>
</div>
@endsection
