@extends('layouts.app')
@section('title', 'Units of Measure')

@section('content')
<div class="card">
    <div class="card-body">
        <div class="d-flex justify-content-between align-items-center mb-3">
            <h6 class="card-title mb-0">Units of Measure</h6>
            <a href="{{ route('uoms.create') }}" class="btn btn-primary">
                <i class="fas fa-plus"></i> Add UOM
            </a>
        </div>

        @if(session('success'))
            <div class="alert alert-success">{{ session('success') }}</div>
        @endif

        @if($errors->any())
            <div class="alert alert-danger">{{ $errors->first() }}</div>
        @endif

        <div class="table-responsive">
            <table class="table table-striped" id="uoms-table">
                <thead>
                    <tr>
                        <th>Code</th>
                        <th>Name</th>
                        <th>Factor to Base</th>
                        <th>Status</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach($uoms as $uom)
                    <tr>
                        <td>{{ $uom->code }}</td>
                        <td>{{ $uom->name }}</td>
                        <td>{{ $uom->formatted_factor }}</td>
                        <td>{!! $uom->status_badge !!}</td>
                        <td>
                            <div class="btn-group" role="group">
                                <a href="{{ route('uoms.show', $uom) }}" class="btn btn-sm btn-outline-info">
                                    <i class="fas fa-eye"></i>
                                </a>
                                <a href="{{ route('uoms.edit', $uom) }}" class="btn btn-sm btn-outline-primary">
                                    <i class="fas fa-edit"></i>
                                </a>
                                <form action="{{ route('uoms.destroy', $uom) }}" method="POST" class="d-inline">
                                    @csrf
                                    @method('DELETE')
                                    <button type="submit" class="btn btn-sm btn-outline-danger" onclick="return confirm('Are you sure?')">
                                        <i class="fas fa-trash"></i>
                                    </button>
                                </form>
                            </div>
                        </td>
                    </tr>
                    @endforeach
                </tbody>
            </table>
        </div>

        <div class="d-flex justify-content-center">
            {{ $uoms->links() }}
        </div>
    </div>
</div>
@endsection

@push('plugin-styles')
<link rel="stylesheet" href="{{ asset('theme/vendors/datatables.net-bs5/dataTables.bootstrap5.css') }}">
@endpush

@push('plugin-scripts')
<script src="{{ asset('theme/vendors/datatables.net/jquery.dataTables.js') }}"></script>
<script src="{{ asset('theme/vendors/datatables.net-bs5/dataTables.bootstrap5.js') }}"></script>
<script>
    $(document).ready(function() {
        $('#uoms-table').DataTable({
            "pageLength": 25,
            "order": [[0, "asc"]]
        });
    });
</script>
@endpush
