@extends('layouts.app')
@section('page_title','Tanks & Stock')
@section('content')
<div class="top-card p-3">
    <div class="d-flex flex-wrap justify-content-between align-items-center gap-2 mb-3">
        <div>
            <h5 class="fw-bold mb-1">Tanks & Stock</h5>
            <small class="text-muted">Purchase increases stock. Sale decreases stock. Manual stock add/edit is available here.</small>
        </div>
        <div class="d-flex gap-2">
            <a href="{{ route('stock.manage') }}" class="btn btn-success"><i class="fa-solid fa-circle-plus"></i> Add / Edit Stock</a>
            <a href="{{ route('tanks.create') }}" class="btn btn-outline-success"><i class="fa-solid fa-plus"></i> New Tank</a>
        </div>
    </div>
    <div class="table-responsive">
        <table class="table align-middle">
            <thead><tr><th>Name</th><th>Fuel</th><th>Capacity</th><th>Current</th><th>Own</th><th>Customer</th><th>Usage</th><th>Action</th></tr></thead>
            <tbody>
                @foreach($tanks as $tank)
                @php $percent = $tank->capacity > 0 ? min(100, ($tank->current_qty / $tank->capacity) * 100) : 0; @endphp
                <tr>
                    <td class="fw-bold">{{ $tank->name }}</td>
                    <td>{{ $tank->fuelType->name_en }}</td>
                    <td>{{ number_format($tank->capacity,3) }}</td>
                    <td class="fw-bold text-success">{{ number_format($tank->current_qty,3) }}</td>
                    <td>{{ number_format($tank->own_qty,3) }}</td>
                    <td>{{ number_format($tank->customer_qty,3) }}</td>
                    <td style="min-width:160px"><div class="progress" style="height:12px"><div class="progress-bar bg-success" style="width:{{ $percent }}%"></div></div></td>
                    <td class="d-flex flex-wrap gap-1">
                        <a class="btn btn-sm btn-outline-success" href="{{ route('stock.manage',['tank_id'=>$tank->id]) }}"><i class="fa-solid fa-circle-plus"></i> Stock</a>
                        <a class="btn btn-sm btn-outline-primary" href="{{ route('tanks.edit',$tank) }}"><i class="fa-solid fa-pen"></i> Tank</a>
                    </td>
                </tr>
                @endforeach
            </tbody>
        </table>
    </div>
    {{ $tanks->links() }}
</div>
@endsection
