@extends('layouts.app')

@section('title', 'Assets')
@section('heading', 'Asset List')

@php
    $serialDirection = ($sort === 'serial' && $direction === 'asc') ? 'desc' : 'asc';
    $serialSortUrl = route('assets.index', ['sort' => 'serial', 'direction' => $serialDirection]);
@endphp

@section('content')
@include('assets.top-submenu')
    <x-card>
        <div class="mb-4 flex justify-between items-center">
            <p class="text-slate-600">Company assets and assignments.</p>
            <a href="{{ route('assets.create') }}" class="inline-flex items-center rounded-lg bg-slate-800 px-4 py-2 text-sm font-medium text-white hover:bg-slate-700"><i class="bi bi-plus-lg me-1"></i>Add Asset</a>
        </div>
        <x-table>
            <x-slot name="head">
                <tr>
                    <th class="px-4 py-3 text-left text-xs font-medium uppercase text-slate-500">Asset Name</th>
                    <th class="px-4 py-3 text-left text-xs font-medium uppercase text-slate-500">Type</th>
                    <th class="px-4 py-3 text-left text-xs font-medium uppercase text-slate-500">
                        <a href="{{ $serialSortUrl }}" class="inline-flex items-center gap-1 hover:text-slate-800">
                            Serial
                            @if($sort === 'serial')
                                <i class="bi {{ $direction === 'asc' ? 'bi-sort-up' : 'bi-sort-down' }}"></i>
                            @else
                                <i class="bi bi-arrow-down-up text-slate-300"></i>
                            @endif
                        </a>
                    </th>
                    <th class="px-4 py-3 text-left text-xs font-medium uppercase text-slate-500">Assigned To</th>
                    <th class="px-4 py-3 text-left text-xs font-medium uppercase text-slate-500">Status</th>
                    <th class="px-4 py-3 text-right text-xs font-medium uppercase text-slate-500">Actions</th>
                </tr>
            </x-slot>
            @forelse($assets as $a)
                <tr>
                    <td class="whitespace-nowrap px-4 py-3 text-sm text-slate-900">{{ $a->name }}</td>
                    <td class="whitespace-nowrap px-4 py-3 text-sm text-slate-600">{{ $a->assetType?->name ?? '—' }}</td>
                    <td class="whitespace-nowrap px-4 py-3 text-sm text-slate-600">{{ $a->serial_number ?? '—' }}</td>
                    <td class="whitespace-nowrap px-4 py-3 text-sm text-slate-600">{{ $a->assignedUser?->name ?? '—' }}</td>
                    <td class="whitespace-nowrap px-4 py-3 text-sm"><x-badge :status="$a->status">{{ $a->status }}</x-badge></td>
                    <td class="whitespace-nowrap px-4 py-3 text-right text-sm">
                        <a href="{{ route('assets.edit', $a) }}" class="btn-icon-action btn-icon-action--edit" title="Edit" aria-label="Edit"><i class="bi bi-pencil-square"></i></a>
                    </td>
                </tr>
            @empty
                <tr><td colspan="6" class="px-4 py-8 text-center text-sm text-slate-500">No assets.</td></tr>
            @endforelse
        </x-table>
        @if($assets->hasPages())<div class="mt-4">{{ $assets->links() }}</div>@endif
    </x-card>
@endsection
