@extends('layouts.app')

@section('title', 'Unit Management')

@section('content')
<div class="walton-card walton-animated">
    <div class="walton-card-header">
        <i class="fas fa-weight"></i> Unit Management
        <div class="float-end">
            <a href="{{ route('settings.units.create') }}" class="walton-btn walton-btn-gold btn-sm">
                <i class="fas fa-plus-circle me-2"></i>Add New Unit
            </a>
        </div>
    </div>
    <div class="walton-card-body">
        <table class="walton-table">
            <thead>
                <tr>
                    <th>SL</th>
                    <th>Name</th>
                    <th>Code</th>
                    <th>Symbol</th>
                    <th>Description</th>
                    <th>Status</th>
                    <th>Actions</th>
                </tr>
            </thead>
            <tbody>
                @forelse($units as $key => $unit)
                <tr>
                    <td>{{ $key + 1 }}</td>
                    <td><strong>{{ $unit->name }}</strong></td>
                    <td><code>{{ $unit->code }}</code></td>
                    <td><span class="badge bg-info">{{ $unit->symbol }}</span></td>
                    <td>{{ Str::limit($unit->description, 50) }}</td>
                    <td>{!! $unit->status_badge !!}</td>
                    <td>
                        <a href="{{ route('settings.units.edit', $unit) }}" class="walton-btn walton-btn-primary btn-sm">
                            <i class="fas fa-edit"></i>
                        </a>
                        <form action="{{ route('settings.units.destroy', $unit) }}" method="POST" class="d-inline">
                            @csrf
                            @method('DELETE')
                            <button type="submit" class="walton-btn walton-btn-danger btn-sm" 
                                    onclick="return confirm('Are you sure?')">
                                <i class="fas fa-trash"></i>
                            </button>
                        </form>
                    </td>
                </tr>
                @empty
                <tr>
                    <td colspan="7" class="text-center">No units found.</td>
                </tr>
                @endforelse
            </tbody>
        </table>
        
        <div class="mt-3">
            {{ $units->links() }}
        </div>
    </div>
</div>
@endsection