@extends('layouts.app')

@section('title', 'Manufacturing - Work Orders')

@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">Manufacturing</li>
                    </ol>
                </div>
                <h4 class="page-title">Manufacturing - Work Orders</h4>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-header">
                    <h4 class="header-title">Work Orders</h4>
                    <p class="text-muted mb-0">Manage manufacturing work orders and track production progress</p>
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <table id="work-orders-table" class="table table-striped table-centered mb-0">
                            <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>Batch No</th>
                                    <th>Item</th>
                                    <th>Planned Qty</th>
                                    <th>Warehouse</th>
                                    <th>Status</th>
                                    <th>Due Date</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() {
    $('#work-orders-table').DataTable({
        processing: true,
        serverSide: false,
        ajax: '{{ route("manufacturing.work-orders") }}',
        columns: [
            {data: 'id', name: 'id'},
            {data: 'batch_no', name: 'batch_no'},
            {data: 'item_name', name: 'item_name'},
            {data: 'qty_planned', name: 'qty_planned'},
            {data: 'warehouse_name', name: 'warehouse_name'},
            {data: 'status_badge', name: 'status'},
            {data: 'due_date', name: 'due_date'},
            {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 work orders found"
        }
    });
});
</script>
@endpush
