@extends('layouts.app')

@section('title', 'Fixed Assets')

@section('content')
    <x-page-head title="Fixed Assets Register" subtitle="Buildings, vehicles & equipment with depreciation">
        <x-slot:actions>
            <a href="{{ route('accounting.fixed-assets.create') }}" class="btn btn-primary">Register Asset</a>
        </x-slot:actions>
    </x-page-head>

    <x-panel>
        @if ($assets->isEmpty())
            <x-empty-state title="No fixed assets" message="Register buildings, vehicles and equipment here.">
                <x-slot:action>
                    <a href="{{ route('accounting.fixed-assets.create') }}" class="btn btn-primary">Register asset</a>
                </x-slot:action>
            </x-empty-state>
        @else
            <div class="table-wrap">
                <table>
                    <thead>
                        <tr>
                            <th>Code</th>
                            <th>Name</th>
                            <th>Category</th>
                            <th>Purchase Cost</th>
                            <th>Accum. Depreciation</th>
                            <th>Book Value</th>
                            <th>Status</th>
                            <th></th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach ($assets as $asset)
                            <tr>
                                <td>{{ $asset->asset_code }}</td>
                                <td>{{ $asset->name }}</td>
                                <td>{{ $asset->category ?? '—' }}</td>
                                <td>{{ number_format($asset->purchase_cost, 2) }}</td>
                                <td>{{ number_format($asset->accumulated_depreciation, 2) }}</td>
                                <td>{{ number_format($asset->book_value, 2) }}</td>
                                <td><x-badge variant="blue">{{ $asset->status }}</x-badge></td>
                                <td style="white-space:nowrap;">
                                    <a href="{{ route('accounting.fixed-assets.edit', $asset) }}" class="btn btn-ghost btn-sm">Edit</a>
                                    @if ($asset->status === 'active')
                                        <form method="POST" action="{{ route('accounting.fixed-assets.depreciate', $asset) }}" style="display:inline;">
                                            @csrf
                                            <button type="submit" class="btn btn-outline btn-sm">Run Depreciation</button>
                                        </form>
                                    @endif
                                </td>
                            </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>
            <div style="margin-top:16px;">{{ $assets->links() }}</div>
        @endif
    </x-panel>
@endsection
