@extends('layouts.app')
@section('title','Fixed Assets')
@section('content')
<x-ui.page-toolbar title="Fixed Assets" description="Register, depreciate, maintain and report company assets." :breadcrumbs="[['label'=>'Dashboard','url'=>route('dashboard')],['label'=>'Fixed Assets']]">
<x-slot:actions>
    <a class="mf-btn" href="{{ route('fixed-assets.reports') }}">Asset Reports</a>
    @if(auth()->user()->can('fixed-assets.manage'))<a class="mf-btn mf-btn-primary" href="{{ route('fixed-assets.create') }}">Register Asset</a>@endif
</x-slot:actions>
</x-ui.page-toolbar>

<div class="grid gap-3 md:grid-cols-4 mb-4">
<div class="mf-card mf-card-body"><div class="text-xs text-muted-foreground">Assets</div><div class="mt-1 text-xl font-semibold">{{ number_format($summary['count']) }}</div></div>
<div class="mf-card mf-card-body"><div class="text-xs text-muted-foreground">Acquisition cost</div><div class="mt-1 text-xl font-semibold">{{ number_format((float)$summary['cost'],2) }}</div></div>
<div class="mf-card mf-card-body"><div class="text-xs text-muted-foreground">Accumulated depreciation</div><div class="mt-1 text-xl font-semibold">{{ number_format((float)$summary['accumulated'],2) }}</div></div>
<div class="mf-card mf-card-body"><div class="text-xs text-muted-foreground">Net book value</div><div class="mt-1 text-xl font-semibold">{{ number_format((float)$summary['book_value'],2) }}</div></div>
</div>

<div class="mf-card mf-card-body mb-4">
<form method="GET" class="grid gap-2 md:grid-cols-5">
<div class="md:col-span-2"><label class="mf-field-label">Search</label><input class="mf-input" name="q" value="{{ request('q') }}" placeholder="Asset number, name, category or serial"></div>
<div><label class="mf-field-label">Branch</label><select class="mf-input" name="branch_id"><option value="">All accessible branches</option>@foreach($branches as $branch)<option value="{{ $branch->id }}" @selected((string)request('branch_id')===(string)$branch->id)>{{ $branch->name }}</option>@endforeach</select></div>
<div><label class="mf-field-label">Status</label><select class="mf-input" name="status"><option value="">All statuses</option>@foreach(\App\Models\FixedAsset::STATUSES as $value=>$label)<option value="{{ $value }}" @selected(request('status')===$value)>{{ $label }}</option>@endforeach</select></div>
<div class="flex items-end gap-2"><button class="mf-btn mf-btn-primary flex-1">Filter</button><a class="mf-btn" href="{{ route('fixed-assets.index') }}">Clear</a></div>
</form>
</div>

<div class="mf-card"><div class="mf-table-frame border-0"><table class="mf-table"><thead><tr><th>Asset</th><th>Category</th><th>Branch / Location</th><th>Acquired</th><th class="text-right">Cost</th><th class="text-right">Book Value</th><th>Status</th><th>Maintenance</th></tr></thead><tbody>
@forelse($assets as $asset)
<tr>
<td><a class="font-medium text-primary hover:underline" href="{{ route('fixed-assets.show',$asset) }}">{{ $asset->asset_number }}</a><div class="text-xs">{{ $asset->name }}</div>@if($asset->serial_number)<div class="text-[11px] text-muted-foreground">Serial: {{ $asset->serial_number }}</div>@endif</td>
<td>{{ $asset->category }}@if($asset->custodian)<div class="text-xs text-muted-foreground">{{ $asset->custodian->name }}</div>@endif</td>
<td>{{ $asset->branch->name }}<div class="text-xs text-muted-foreground">{{ $asset->location ?: '—' }}</div></td>
<td>{{ $asset->acquisition_date->format('d M Y') }}</td>
<td class="text-right">{{ number_format((float)$asset->acquisition_cost,2) }}</td>
<td class="text-right font-medium">{{ number_format((float)$asset->book_value,2) }}</td>
<td><span class="mf-badge mf-badge-muted">{{ \App\Models\FixedAsset::STATUSES[$asset->status] ?? str($asset->status)->replace('_',' ')->title() }}</span></td>
<td>{{ $asset->next_maintenance_date?->format('d M Y') ?? '—' }}</td>
</tr>
@empty<tr><td colspan="8" class="text-center text-muted-foreground">No fixed assets found.</td></tr>@endforelse
</tbody></table></div></div>
<div class="mt-4">{{ $assets->links() }}</div>
@endsection
