@extends('layouts.app')

@section('title', 'Locations')

@section('content')
<div class="page-content">
    <div class="row">
        <div class="col-md-12">
            <div class="page-title-box">
                <div class="page-title-right">
                    <ol class="breadcrumb m-0">
                        <li class="breadcrumb-item"><a href="{{ route('dashboard') }}">Dashboard</a></li>
                        <li class="breadcrumb-item active">Locations</li>
                    </ol>
                </div>
                <h4 class="page-title">Locations</h4>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-header d-flex justify-content-between align-items-center">
                    <h4 class="header-title">Warehouse Locations</h4>
                    <a href="{{ route('locations.create') }}" class="btn btn-primary">
                        <i class="fas fa-plus"></i> Add Location
                    </a>
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <table id="locations-table" class="table table-striped table-centered mb-0">
                            <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>Warehouse</th>
                                    <th>Location Name</th>
                                    <th>Barcode</th>
                                    <th>Stock Movements</th>
                                    <th>Created</th>
                                    <th>Actions</th>
                                </tr>
                            </thead>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

@push('plugin-scripts')
<script src="https://cdn.datatables.net/1.11.5/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.11.5/js/dataTables.bootstrap5.min.js"></script>
@endpush

@push('plugin-styles')
<link href="https://cdn.datatables.net/1.11.5/css/dataTables.bootstrap5.min.css" rel="stylesheet">
@endpush

@push('scripts')
<script>
$(document).ready(function() {
    $('#locations-table').DataTable({
        processing: true,
        serverSide: false,
        ajax: '{{ route("locations.data") }}',
        columns: [
            {data: 'id', name: 'id'},
            {data: 'warehouse_name', name: 'warehouse_name'},
            {data: 'name', name: 'name'},
            {data: 'barcode_display', name: 'barcode'},
            {data: 'stock_movements_count', name: 'stock_movements'},
            {data: 'created_at', name: 'created_at'},
            {data: 'actions', name: 'actions', orderable: false, searchable: false}
        ],
        order: [[0, 'desc']],
        pageLength: 25,
        language: {
            search: "Search:",
            lengthMenu: "Show _MENU_ entries per page",
            info: "Showing _START_ to _END_ of _TOTAL_ entries",
            infoEmpty: "Showing 0 to 0 of 0 entries",
            infoFiltered: "(filtered from _MAX_ total entries)",
            processing: "Processing...",
            emptyTable: "No locations found"
        }
    });
});
</script>
@endpush
