<x-ui.layout.page :title="$asset->name" :subtitle="$asset->asset_code" page-icon="fe fe-monitor">
    <x-slot:actions>@can('update', $asset)<x-ui.buttons.secondary :href="route('hr.assets.edit', $asset)">
        {{ __('common.edit') }}</x-ui.buttons.secondary>@endcan</x-slot:actions>
    <div class="card mb-3"><div class="card-body">
        <strong>{{ __('assets.fields.status') }}:</strong> {{ __('assets.statuses.'.$asset->status) }}
        <span class="ms-4"><strong>{{ __('assets.fields.employee') }}:</strong>
            {{ $asset->currentEmployee?->full_name ?? '—' }}</span>
    </div></div>
    @can('manage', $asset)
        <div class="card mb-3"><div class="card-body"><div class="row g-2">
            @if ($asset->status === 'available')
                <form method="POST" action="{{ route('hr.assets.assign', $asset) }}" class="col-md-6 d-flex gap-2">@csrf
                    <select name="employee_id" class="form-select" required>
                        <option value="">{{ __('assets.actions.select_employee') }}</option>
                        @foreach ($employees as $id => $name)<option value="{{ $id }}">{{ $name }}</option>@endforeach
                    </select><x-ui.buttons.primary type="submit">{{ __('assets.actions.assign') }}</x-ui.buttons.primary>
                </form>
            @elseif ($asset->status === 'assigned')
                <form method="POST" action="{{ route('hr.assets.transfer', $asset) }}" class="col-md-6 d-flex gap-2">@csrf
                    <select name="employee_id" class="form-select" required>
                        @foreach ($employees as $id => $name)<option value="{{ $id }}">{{ $name }}</option>@endforeach
                    </select><x-ui.buttons.secondary type="submit">{{ __('assets.actions.transfer') }}</x-ui.buttons.secondary>
                </form>
                <form method="POST" action="{{ route('hr.assets.return', $asset) }}" class="col-auto">@csrf
                    <x-ui.buttons.primary type="submit">{{ __('assets.actions.return') }}</x-ui.buttons.primary>
                </form>
            @endif
            @if (!in_array($asset->status, ['damaged', 'retired', 'lost']))
                <form method="POST" action="{{ route('hr.assets.damage', $asset) }}" class="col-auto">@csrf
                    <x-ui.buttons.danger type="submit">{{ __('assets.actions.damage') }}</x-ui.buttons.danger>
                </form>
            @endif
        </div></div></div>
    @endcan
    <x-ui.table.table :columns="[
        ['label' => __('assets.fields.action')], ['label' => __('assets.fields.employee')],
        ['label' => __('assets.fields.created_at')], ['label' => __('assets.fields.notes')],
    ]">
        @forelse ($asset->movements as $movement)
            <x-ui.table.row><td>{{ __('assets.actions.'.$movement->action) }}</td>
                <td>{{ $movement->employee?->full_name ?? '—' }}</td>
                <td>{{ $movement->created_at?->format('Y-m-d H:i') }}</td><td>{{ $movement->notes ?: '—' }}</td>
            </x-ui.table.row>
        @empty <x-ui.table.row><td colspan="4">{{ __('assets.movements_empty') }}</td></x-ui.table.row>
        @endforelse
    </x-ui.table.table>
</x-ui.layout.page>
