@extends('layouts.app')
@section('title', 'Demand Forecast')
@section('content')
<section class="content-header"><h1>Parts Demand &amp; Service Forecast <small>historical trend</small></h1></section>
<section class="content">
    <div class="row">
        <div class="col-md-3">
            <div class="info-box"><span class="info-box-icon bg-aqua"><i class="fa fa-calendar"></i></span>
                <div class="info-box-content"><span class="info-box-text">Service reminders due (30d)</span>
                    <span class="info-box-number">{{ $serviceLoad['due'] }}</span></div></div>
        </div>
        <div class="col-md-9">
            <form method="GET" class="form-inline pull-right" style="margin-top:8px;">
                <label>History window (months):</label>
                <input type="number" name="months" value="{{ $months }}" min="1" max="24" class="form-control" style="width:90px;">
                <button class="btn btn-default">Recompute</button>
            </form>
        </div>
    </div>

    @component('components.widget', ['class' => 'box-primary', 'title' => 'Parts demand forecast (next month)'])
        <table class="table table-bordered table-striped">
            <thead><tr><th>Part</th><th class="text-right">Used ({{ $months }}m)</th><th class="text-right">Monthly avg</th><th class="text-right">Forecast next</th></tr></thead>
            <tbody>
                @forelse($parts as $p)
                    <tr><td>{{ $p['part'] }}</td>
                        <td class="text-right">{{ number_format($p['total_qty'], 2) }}</td>
                        <td class="text-right">{{ number_format($p['monthly_avg'], 2) }}</td>
                        <td class="text-right"><strong>{{ $p['forecast_next'] }}</strong></td></tr>
                @empty
                    <tr><td colspan="4" class="text-muted">Not enough parts-consumption history yet.</td></tr>
                @endforelse
            </tbody>
        </table>
        <p class="text-muted" style="font-size:12px;">Heuristic moving-average over the selected window. A natural place to delegate to AiCore for richer prediction.</p>
    @endcomponent
</section>
@endsection
