@extends('layouts.app')
@section('page_title',$tank->exists?'Edit Tank':'New Tank')
@section('content')
<form method="POST" action="{{ $tank->exists ? route('tanks.update',$tank) : route('tanks.store') }}">
@csrf
@if($tank->exists) @method('PUT') @endif
<div class="top-card p-3">
    <div class="d-flex justify-content-between align-items-center mb-3">
        <div><h5 class="fw-bold mb-1">{{ $tank->exists ? 'Edit Tank Information' : 'Create New Tank' }}</h5><small class="text-muted">This form is for tank name, capacity and fuel type. Use Add/Edit Stock for stock quantity.</small></div>
        @if($tank->exists)<a href="{{ route('stock.manage',['tank_id'=>$tank->id]) }}" class="btn btn-success"><i class="fa-solid fa-oil-can"></i> Add / Edit Stock</a>@endif
    </div>
    <div class="row g-3">
        <div class="col-md-6"><label class="easy-label required">Name</label><input name="name" value="{{ old('name',$tank->name) }}" class="form-control form-control-lg" required></div>
        <div class="col-md-6"><label class="easy-label required">Fuel</label><select name="fuel_type_id" class="form-select form-select-lg">@foreach($fuelTypes as $f)<option value="{{ $f->id }}" @selected(old('fuel_type_id',$tank->fuel_type_id)==$f->id)>{{ $f->name_en }}</option>@endforeach</select></div>
        <div class="col-md-6"><label class="easy-label required">Capacity</label><input type="number" step="0.001" name="capacity" value="{{ old('capacity',$tank->capacity) }}" class="form-control form-control-lg" required></div>
        <div class="col-md-6"><label class="easy-label">Location</label><input name="location" value="{{ old('location',$tank->location) }}" class="form-control form-control-lg"></div>
        @if($tank->exists)
        <div class="col-md-4"><label class="easy-label">Current Stock</label><input value="{{ number_format($tank->current_qty,3) }}" class="form-control form-control-lg" readonly></div>
        <div class="col-md-4"><label class="easy-label">Own Stock</label><input value="{{ number_format($tank->own_qty,3) }}" class="form-control form-control-lg" readonly></div>
        <div class="col-md-4"><label class="easy-label">Customer Stock</label><input value="{{ number_format($tank->customer_qty,3) }}" class="form-control form-control-lg" readonly></div>
        @endif
        <div class="col-12"><label class="form-check"><input type="checkbox" name="is_active" value="1" class="form-check-input" @checked(old('is_active',$tank->is_active ?? true))> Active</label></div>
        <div class="col-12 text-end"><button class="btn btn-success btn-lg"><i class="fa-solid fa-save"></i> Save Tank</button></div>
    </div>
</div>
</form>
@endsection
